wp-go/internal/wpconfig/term.go

31 lines
688 B
Go
Raw Normal View History

2022-11-17 08:29:39 +00:00
package wpconfig
2022-11-15 03:11:08 +00:00
import (
"context"
2023-01-13 06:04:32 +00:00
"github/fthvgb1/wp-go/internal/pkg/models"
2023-01-12 12:42:16 +00:00
"github/fthvgb1/wp-go/model"
2022-11-15 03:11:08 +00:00
"github/fthvgb1/wp-go/safety"
)
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
}