Guide

Term Meta Fields Ability

Ability for creating or updating the custom field configuration attached to a taxonomy.


native-custom-fields/save-term-meta-fields

Creates or updates the field configuration displayed on the term edit pages of a given taxonomy. If a configuration already exists for the given taxonomy, it is overwritten.


Input Schema

{
  "type": "object",
  "required": ["taxonomy", "sections"]
}

Top-level Properties

PropertyRequiredTypeDescription
taxonomyYesstringSlug of the taxonomy to attach fields to
sectionsYesarrayArray of section definitions

Section Schema

{
  "type": "object",
  "required": ["section_name", "section_title"]
}
PropertyRequiredTypeDefaultDescription
section_nameYesstringUnique slug for the section
section_titleYesstringSection title displayed in the admin screen
section_iconNostring"admin-generic"Dashicon name without the dashicons- prefix (e.g. "tag")
fieldsNoarray[]Fields inside this section (see field-schema.md)

Output Schema

{
  "status": true,
  "message": "..."
}
FieldTypeDescription
statusbooleantrue on success, false on failure
messagestringResult description or error message

Internal Behaviour

  • taxonomy is sanitized with sanitize_key().
  • section_name is sanitized with sanitize_key().
  • section_title is sanitized with sanitize_text_field().
  • Builder slug format: native_custom_fields_term_meta_fields_builder_{taxonomy}
  • On success, the same values are also stored via OptionService::saveOptions().
  • Field values are stored at runtime in the wp_termmeta table using the field name as the meta key.
  • Sections are internally tagged with fieldType: "section" before being passed to TermMetaService::saveTermMetaFieldsConfig().

Example

{
  "taxonomy": "genre",
  "sections": [
    {
      "section_name": "genre_details",
      "section_title": "Genre Details",
      "section_icon": "tag",
      "fields": [
        {
          "fieldType": "textarea",
          "name": "long_description",
          "fieldLabel": "Long Description",
          "field_custom_info": {
            "rows": 5,
            "placeholder": "Describe this genre in detail"
          }
        },
        {
          "fieldType": "media_library",
          "name": "genre_image",
          "fieldLabel": "Genre Image"
        },
        {
          "fieldType": "color_picker",
          "name": "genre_color",
          "fieldLabel": "Genre Color",
          "default": "#3498db"
        }
      ]
    }
  ]
}

Success Response

{
  "status": true,
  "message": "Term meta fields saved successfully."
}

Error Responses

{ "status": false, "message": "taxonomy is required." }
{ "status": false, "message": "sections is required." }

Permission

Requires the manage_options WordPress capability.


Was this helpful?