wp-go/config/term.go
2022-11-15 11:11:08 +08:00

31 lines
667 B
Go

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
}