wp post meta
Overview
Manage custom post meta (stored in wp_postmeta) for any post or custom post type. Post meta holds plugin-specific settings, custom fields, SEO data, and any key-value data attached to a post.
Subcommands
| Subcommand | Description |
|---|---|
wp post meta get ID KEY | Retrieve a meta value |
wp post meta add ID KEY VALUE | Add new meta entry |
wp post meta update ID KEY VALUE | Update existing meta |
wp post meta delete ID KEY | Delete a meta key |
wp post meta list ID | List all meta for a post |
wp post meta patch ID KEY SUBKEY VALUE | Patch subkey in serialized meta |
wp post meta pluck ID KEY SUBKEY | Get subkey from serialized meta |
Basic Usage
Get a meta value
wp post meta get 42 _yoast_wpseo_title
Add new meta
wp post meta add 42 featured_video_url "https://youtube.com/watch?v=abc"
Update existing meta
wp post meta update 42 _price "29.99"
Delete meta key
wp post meta delete 42 _temp_flag
List all meta
wp post meta list 42 --format=table
Real-World Scenarios
Scenario 1: Set SEO title across all posts missing it
for id in $(wp post list --post_type=post --post_status=publish --field=ID); do
EXISTING=$(wp post meta get "$id" _yoast_wpseo_title 2>/dev/null)
if [[ -z "$EXISTING" ]]; then
TITLE=$(wp post get "$id" --field=post_title)
wp post meta add "$id" _yoast_wpseo_title "$TITLE | My Site"
fi
done
Scenario 2: Update WooCommerce product price in bulk
for id in $(wp post list --post_type=product --post_status=publish --field=ID); do
OLD=$(wp post meta get "$id" _price)
NEW=$(echo "$OLD * 1.10" | bc) # 10% increase
wp post meta update "$id" _price "$NEW"
wp post meta update "$id" _regular_price "$NEW"
done
Scenario 3: Audit all posts with a specific meta flag
for id in $(wp post list --field=ID --post_type=post); do
VAL=$(wp post meta get "$id" _needs_review 2>/dev/null)
if [[ "$VAL" == "1" ]]; then
TITLE=$(wp post get "$id" --field=post_title)
echo "Needs review: ID $id — $TITLE"
fi
done
Best Practices
- Use
listfirst to discover existing meta keys before adding duplicates. - Use
patchfor serialized/array meta data instead of overwriting the whole value. - Prefix custom meta keys (e.g.
_mysite_feature) to avoid collisions with plugins.
Quick Reference
wp post meta get <id> <key> # Get value
wp post meta add <id> <key> <value> # Add new
wp post meta update <id> <key> <value> # Update
wp post meta delete <id> <key> # Delete
wp post meta list <id> --format=table # All meta
Next Steps
wp post get— view core post fields.wp post term— manage taxonomy terms on a post.