WordPress Custom Fields is the most usable field ever, we can give many information using custom fields, we can added custom image post, added some content and many many things we can do.
Sometime we need to Get all wordpress custom fields from a page or a post and display it in our post content or page or whatever in our WordPress. Write down this code below in your functions.php theme
Get All Custom Fields Code
<?php
function display_my_customs($id = 0){
//if we want to run this function on a page of our choosing them the next section is skipped.
//if not it grabs the ID of the current page and uses it from now on.
if ($id == 0) :
global $wp_query;
$content_array = $wp_query->get_queried_object();
$id = $content_array->ID;
endif;
//knocks the first 3 elements off the array as they are WP entries and i dont want them.
$first_array = array_slice(get_post_custom_keys($id), 3);
//first loop puts everything into an array, but its badly composed
foreach ($first_array as $key => $value) :
$second_array[$value] = get_post_meta($id, $value, FALSE);
//so the second loop puts the data into a associative array
foreach($second_array as $second_key => $second_value) :
$result[$second_key] = $second_value[0];
endforeach;
endforeach;
//and returns the array.
return $result;
}
?>
This code will get all your custom field and display it, to display or using Get All Custom Fields in WordPress code use this simple steps
<?php $result = display_my_customs(); echo $result['my_meta_key'];?>
this code original created by LiveXP




Pingback: Tweets that mention How To Get all WordPress custom fields from a page or a post # WordPress Tricks & Tips -- Topsy.com
…or, you could just do this:
That would be:
the_meta();
…wrapped in PHP tags.
… makes heavy use of WordPress’ custom fields … sort of understood custom fields I now get … Using WordPress Custom Fields (in 2 parts) » Critical Flare; 65 Of The Best WordPress
I agree.
is a lot simpler. It does display all< of the meta data/custom fields though. However, that’s what I personally needed. Using “More Fields” or other plugins, you can always make hidden fields to not show them, and use the same technique.
That can be put within the single.php/post.php above content() or inside: content(meta());
To get the custom fields into the Excerpt, it can be put into formatting.php
Cheers!