WP Munk > Blog > Beginner's Guides > How to display all custom fields (name AND value) in a post?

How to display all custom fields (name AND value) in a post?

You are working on a custom WordPress theme that uses lots and lots of custom fields and you suddenly want to see what all custom fields are assigned to any post.  You can do by going into the dashboard of the site and editing the specific post but what if you want to show it on the front-end of site on the single post template?

What if you have tons of custom fields and just want to show them all on the single post without specifying specific custom field name/key?

In that case you can use the snippet below inside the post loop to show all the custom fields that are attached to a post:

<?php
$custom_fields = get_post_custom();

foreach ( $custom_fields as $field_key => $field_values ) {
	foreach ( $field_values as $key => $value )
		echo $field_key . ' - ' . $value . '<br />';
}
?>

Source

About The Author


Mohammad Tajim

Hello, I am Mohammad Tajim a WordPress Developer with over 14 years of experience building WP Products. I made Munk WordPress Theme and other themes available at metricthemes.com. Follow me on twitter @tajim

More free templates for download at: Google Slides Themes

Copyright © 2020 WP Munk.
Built with Munk and Powered by WordPress.