2024-05-09 20:06:01 +00:00
|
|
|
package wordpress
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"federated.computer/wp-sync-slowtwitch/utilities"
|
|
|
|
"net/url"
|
|
|
|
)
|
|
|
|
|
|
|
|
type CategoryData struct {
|
|
|
|
Id int `json:"id"`
|
|
|
|
ParentId int `json:"parent_id"`
|
|
|
|
Name string `json:"name"`
|
|
|
|
ParentName string `json:"parent_name"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func GetCategory(name, baseUrl, user, pass string) (CategoryData, bool) {
|
2024-05-15 23:37:42 +00:00
|
|
|
endpoint := baseUrl + "wp/v2/categories?search=" + url.QueryEscape(name)
|
2024-05-09 20:06:01 +00:00
|
|
|
response := utilities.GetHttpRequestToWordpress(endpoint, user, pass)
|
|
|
|
var categoryData []CategoryData
|
|
|
|
err := json.Unmarshal(response, &categoryData)
|
|
|
|
utilities.CheckError(err)
|
|
|
|
for _, category := range categoryData {
|
|
|
|
if category.Name == name {
|
|
|
|
return category, true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return CategoryData{}, false
|
|
|
|
}
|