I’m trying to display post meta values and post meta keys, If only one value is to be display I can used the simple function get_post_meta() but what I need now is to post all post meta data with the same post_id. I tried using foreach loop but nothing displays. Can you please check my code?
function wpt_calendar_display()
{
global $post;
$columns = array(
'date_event' => 'Date',
'name_event' => 'Event'
);
register_column_headers('list-header_events', $columns);
$event_name = get_post_meta( $post->ID, '_event_name' );
// $event_date = get_post_meta( $post->ID, '_event_date', false );
$return .= "<table class="widefat">";
$return .= "<tr>";
$return .= print_column_headers('list-header_events');
$return .= "</tr>";
$return .= "<tr>";
if (!empty($event_name))
foreach($event_name as $e_name)
{
$return .= "<td>";
$return .= $e_name;
$return .="</td>";
}
$return .= "<td>";
$return .= "</td>";
$return .= "</tr>";
$return .= "</table>";
return $return;
}
for example:
For reference: See Codex
To get all rows, don’t specify the key. Try this:
Hope it helps!
Key = Youtube videos all meta keys for youtube videos and value
As of Jan 2020 and WordPress v5.3.2, I confirm the following works fine.
It will include the field keys with their equivalent underscore keys as well, but I guess if you properly “enum” your keys in your code, that should be no problem:As the
print_r(meta_values);
gives:Hope that helps someone, go make a ruckus!
I use it in form of a meta box. Here is a function that dumps values of all the meta data for post.
Hope it helps. You can use it inside a meta box or at the front-end.
WordPress have the function get_metadata this get all meta of object (Post, term, user…)
Just use