wp-go/models/globalInit.go

51 lines
1.1 KiB
Go
Raw Normal View History

2022-09-01 02:31:11 +00:00
package models
var Options = make(map[string]string)
2022-09-15 14:35:32 +00:00
var Terms = map[uint64]WpTerms{}
var TermTaxonomy = map[uint64]WpTermTaxonomy{}
2022-10-13 07:59:43 +00:00
var TotalRaw int
2022-09-01 02:31:11 +00:00
func InitOptions() error {
ops, err := SimpleFind[WpOptions](SqlBuilder{{"autoload", "yes"}}, "option_name, option_value")
if err != nil {
return err
}
if len(ops) == 0 {
ops, err = SimpleFind[WpOptions](nil, "option_name, option_value")
if err != nil {
return err
}
}
for _, options := range ops {
Options[options.OptionName] = options.OptionValue
}
return nil
}
2022-09-05 01:49:14 +00:00
func InitTerms() (err error) {
2022-09-15 14:35:32 +00:00
terms, err := Find[WpTerms](nil, "*", "", nil, nil, 0)
if err != nil {
return err
}
2022-09-13 03:23:28 +00:00
for _, wpTerms := range terms {
2022-09-15 14:35:32 +00:00
Terms[wpTerms.TermId] = wpTerms
}
termTax, err := Find[WpTermTaxonomy](nil, "*", "", nil, nil, 0)
if err != nil {
return err
}
for _, taxonomy := range termTax {
TermTaxonomy[taxonomy.TermTaxonomyId] = taxonomy
2022-09-13 03:23:28 +00:00
}
2022-10-13 07:59:43 +00:00
r, err := Find[WpPosts](SqlBuilder{
{"post_type", "in", ""},
{"post_status", "in", ""},
}, "count(*) ID", "", nil, nil, 0, []any{"post"}, []any{"publish"})
if err != nil {
panic(err)
}
TotalRaw = int(r[0].Id)
2022-09-05 01:49:14 +00:00
return
2022-09-01 02:31:11 +00:00
}