The list_meta() WordPress PHP function outputs a post’s public meta data in the Custom Fields meta box.
Usage
list_meta( $meta );
Custom example
Input:
$meta = array( 'meta_key' => 'post_location', 'meta_value' => 'New York' ); list_meta( $meta );
Output:
Displays the meta key and meta value in the Custom Fields meta box.
Parameters
$meta
(array) (required) – An array of meta data arrays keyed on ‘meta_key’ and ‘meta_value’.
More information
See WordPress Developer Resources: list_meta
Examples
Display post’s meta data
This example shows how to display a post’s meta data in the Custom Fields meta box using list_meta().
$meta_data = array( 'meta_key' => 'post_location', 'meta_value' => 'San Francisco' ); list_meta( $meta_data );
Display multiple meta data
This example demonstrates how to display multiple meta data for a post using list_meta().
$meta_data_1 = array( 'meta_key' => 'post_location', 'meta_value' => 'Los Angeles' ); $meta_data_2 = array( 'meta_key' => 'post_author', 'meta_value' => 'John Doe' ); list_meta( $meta_data_1 ); list_meta( $meta_data_2 );
Display meta data with HTML
This example displays a post’s meta data with additional HTML formatting using list_meta().
$meta_data = array( 'meta_key' => 'post_location', 'meta_value' => '<strong>Paris</strong>' ); list_meta( $meta_data );
Display meta data from custom post type
This example retrieves and displays meta data from a custom post type using list_meta().
$custom_post_id = 123; $meta_data = get_post_meta( $custom_post_id, 'post_location', true ); list_meta( $meta_data );
Display meta data with a custom function
This example creates a custom function that retrieves and displays meta data using list_meta().
function display_meta_data( $post_id, $meta_key ) { $meta_data = get_post_meta( $post_id, $meta_key, true ); list_meta( $meta_data ); } $post_id = 456; $meta_key = 'post_location'; display_meta_data( $post_id, $meta_key );