2022-11-05 02:32:57 +00:00
|
|
|
package wp
|
|
|
|
|
|
|
|
import "github/fthvgb1/wp-go/models"
|
2022-09-01 02:31:11 +00:00
|
|
|
|
2022-11-05 14:40:02 +00:00
|
|
|
var Option = make(map[string]string)
|
2022-09-15 14:35:32 +00:00
|
|
|
var Terms = map[uint64]WpTerms{}
|
2022-11-05 14:40:02 +00:00
|
|
|
var TermTaxonomies = map[uint64]TermTaxonomy{}
|
2022-09-01 02:31:11 +00:00
|
|
|
|
|
|
|
func InitOptions() error {
|
2022-11-05 14:40:02 +00:00
|
|
|
ops, err := models.SimpleFind[Options](models.SqlBuilder{{"autoload", "yes"}}, "option_name, option_value")
|
2022-09-01 02:31:11 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if len(ops) == 0 {
|
2022-11-05 14:40:02 +00:00
|
|
|
ops, err = models.SimpleFind[Options](nil, "option_name, option_value")
|
2022-09-01 02:31:11 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for _, options := range ops {
|
2022-11-05 14:40:02 +00:00
|
|
|
Option[options.OptionName] = options.OptionValue
|
2022-09-01 02:31:11 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-09-05 01:49:14 +00:00
|
|
|
func InitTerms() (err error) {
|
2022-11-05 02:32:57 +00:00
|
|
|
terms, err := models.SimpleFind[WpTerms](nil, "*")
|
2022-09-15 14:35:32 +00:00
|
|
|
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
|
|
|
|
}
|
2022-11-05 14:40:02 +00:00
|
|
|
termTax, err := models.SimpleFind[TermTaxonomy](nil, "*")
|
2022-09-15 14:35:32 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
for _, taxonomy := range termTax {
|
2022-11-05 14:40:02 +00:00
|
|
|
TermTaxonomies[taxonomy.TermTaxonomyId] = taxonomy
|
2022-09-13 03:23:28 +00:00
|
|
|
}
|
2022-09-05 01:49:14 +00:00
|
|
|
return
|
2022-09-01 02:31:11 +00:00
|
|
|
}
|