wp-go/config/term.go

31 lines
667 B
Go
Raw Normal View History

2022-11-15 03:11:08 +00:00
package config
import (
"context"
"github/fthvgb1/wp-go/models"
"github/fthvgb1/wp-go/models/wp"
"github/fthvgb1/wp-go/safety"
)
var Terms safety.Map[uint64, wp.WpTerms]
var TermTaxonomies safety.Map[uint64, wp.TermTaxonomy]
func InitTerms() (err error) {
ctx := context.Background()
terms, err := models.SimpleFind[wp.WpTerms](ctx, nil, "*")
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
}