Skip to main content

wp term meta

Overview

Manage custom meta data attached to taxonomy terms, stored in wp_termmeta. Term meta holds plugin-specific settings, ACF custom fields, SEO descriptions, and any key-value data attached to categories, tags, or custom terms.

Subcommands

SubcommandDescription
wp term meta get ID KEYRetrieve a meta value
wp term meta add ID KEY VALUEAdd new meta
wp term meta update ID KEY VALUEUpdate existing meta
wp term meta delete ID KEYDelete a meta key
wp term meta list IDList all meta for a term
wp term meta patch ID KEY SUBKEY VALUEUpdate subkey in serialized meta
wp term meta pluck ID KEY SUBKEYRead subkey from serialized meta

Basic Usage

Get a meta value

wp term meta get 12 term_image_url

Add new meta

wp term meta add 12 term_color "#FF5733"

Update existing meta

wp term meta update 12 term_icon "fa-laptop"

Delete meta key

wp term meta delete 12 _temp_flag

List all meta for a term

wp term meta list 12 --format=table

Real-World Scenarios

Scenario 1: Add category images for WooCommerce

for id in $(wp term list product_cat --field=term_id); do
wp term meta add "$id" thumbnail_id "0"
done

Scenario 2: Audit ACF term meta fields

for id in $(wp term list category --field=term_id); do
NAME=$(wp term get category "$id" --field=name)
DESC=$(wp term meta get "$id" _acf_field_description 2>/dev/null)
echo "$NAME: $DESC"
done

Scenario 3: Set term order for custom display

TERMS=($(wp term list category --orderby=name --field=term_id))
POS=1
for id in "${TERMS[@]}"; do
wp term meta update "$id" menu_order "$POS"
((POS++))
done

Best Practices

  1. Use list first to see existing meta before adding duplicates.
  2. Prefix custom meta keys (e.g. _mysite_color) to avoid plugin conflicts.
  3. Use patch for serialized or array meta values.

Quick Reference

wp term meta get <id> <key>             # Get value
wp term meta add <id> <key> <value> # Add new
wp term meta update <id> <key> <value> # Update
wp term meta delete <id> <key> # Delete
wp term meta list <id> --format=table # All meta

Next Steps