A command line interface for WordPress

Docs » Internal API » Output


Render a collection of items as an ASCII table, JSON, CSV, YAML, list of ids, or count.


WP_CLI\Utils\format_items( $format, $items, $fields )
$format (string) Format to use: 'table', 'json', 'csv', 'yaml', 'ids', 'count'
$items (array) An array of items to output.
$fields (array|string) Named fields for each item of data. Can be array or comma-separated list.
@return (null)


Given a collection of items with a consistent data structure:

$items = array(
        'key'   => 'foo',
        'value'  => 'bar',

Render $items as an ASCII table:

WP_CLI\Utils\format_items( 'table', $items, array( 'key', 'value' ) );

# +-----+-------+
# | key | value |
# +-----+-------+
# | foo | bar   |
# +-----+-------+

Or render $items as YAML:

WP_CLI\Utils\format_items( 'yaml', $items, array( 'key', 'value' ) );

# ---
# -
#   key: foo
#   value: bar

Internal API documentation is generated from the WP-CLI codebase on every release. To suggest improvements, please submit a pull request.