wp-go/internal/wpconfig/term.go

31 lines
700 B
Go
Raw Permalink Normal View History

2022-11-17 08:29:39 +00:00
package wpconfig
2022-11-15 03:11:08 +00:00
import (
"context"
"github.com/fthvgb1/wp-go/internal/pkg/models"
"github.com/fthvgb1/wp-go/model"
"github.com/fthvgb1/wp-go/safety"
2022-11-15 03:11:08 +00:00
)
2023-01-13 06:04:32 +00:00
var Terms safety.Map[uint64, models.Terms]
var TermTaxonomies safety.Map[uint64, models.TermTaxonomy]
2022-11-15 03:11:08 +00:00
func InitTerms() (err error) {
ctx := context.Background()
2023-01-13 06:04:32 +00:00
terms, err := model.SimpleFind[models.Terms](ctx, nil, "*")
2022-11-15 03:11:08 +00:00
if err != nil {
return err
}
for _, wpTerms := range terms {
Terms.Store(wpTerms.TermId, wpTerms)
}
2023-01-13 06:04:32 +00:00
termTax, err := model.SimpleFind[models.TermTaxonomy](ctx, nil, "*")
2022-11-15 03:11:08 +00:00
if err != nil {
return err
}
for _, taxonomy := range termTax {
TermTaxonomies.Store(taxonomy.TermTaxonomyId, taxonomy)
}
return
}