wp-go/config/wpconfig/term.go

31 lines
665 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"
"github/fthvgb1/wp-go/models"
"github/fthvgb1/wp-go/models/wp"
"github/fthvgb1/wp-go/safety"
)
2022-11-17 09:44:11 +00:00
var Terms safety.Map[uint64, wp.Terms]
2022-11-15 03:11:08 +00:00
var TermTaxonomies safety.Map[uint64, wp.TermTaxonomy]
func InitTerms() (err error) {
ctx := context.Background()
2022-11-17 09:44:11 +00:00
terms, err := models.SimpleFind[wp.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)
}
termTax, err := models.SimpleFind[wp.TermTaxonomy](ctx, nil, "*")
if err != nil {
return err
}
for _, taxonomy := range termTax {
TermTaxonomies.Store(taxonomy.TermTaxonomyId, taxonomy)
}
return
}