Add new --meta_format to `wp post meta` commands

Open
#142 10 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
php, wordpress
Domain
cli

Research direction

Review the post meta list and post meta get command behavior and their documented --format options first. Resolve the proposed name for the key-value JSON format, then make both commands emit the format expected by the post create and post update meta_input examples and verify the documented command outputs.

Written by the indexing model from the issue text.

Description

command:post-meta-get command:post-meta-list

According to the WP-CLI 1.5.0 Announcement:

The --meta_input option of the post create and post update commands now accepts JSON-formatted arrays, so you can add or update your post and its meta in one go:

$ wp post create --post_title='Title' --post_content='Content.' --meta_input='{"key1":"value1","key2":"value2"}
Success: Created post 123.

Unfortunately, there doesn't seem to be an equivalent export option for post meta list or post meta get.

wp post meta list 123 --fields=meta_key,meta_value --format=json will create [{"meta_key":"foo", "meta_value":"bar}] and not {"foo":"bar"} as shown in the examples for post update and post create.


post meta list

[--format=<format>]
Accepted values: table, csv, json, count. Default: table

post meta get

[--format=<format>]
Accepted values: table, json. Default: table

[--format=<format>]
Render output in a particular format.
---
default: table
options:
– table
– csv
– ids
– json
– count
– yaml

A suggestion has been made to add a new --format=meta_input or similar.

While the argument meta_input makes sense to solve this particular issue (based on import) it doesn't really describe the export type which is <key>:<value> JSON.

  • --format=meta_input
  • --format=json-key-value
  • --format=json-key:value
  • --format=jsonkv
  • --format=json-kv
Dominant language
PHP
Stars
105
Forks
97
Avg merge
2h 1m
Merged PRs (30d)
12

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from wp-cli/entity-command

All issues in wp-cli/entity-command

Similar issues

More PHP issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.