Here's what I am trying to do:

I am trying to get one page in wordpress to pull data from custom fields in other pages. So that when a user creates a page and uses a particular custom field (in this case multiedit_Info), it will populate in the "target" page.

Here's my code that I am working with:

<?php $item = get_post_meta($post->ID, 'multiedit_Info', false); ?>
<div id="info-col">
<?php echo $item; ?>

I am currently using a plugin that create content blocks by using custom fields. And I want to get it so that a user can just create a new page with the custom fields and then have it display in an array on another page.

Not too sure if I am setting this up correctly or not. This is the first time I've ever used it so any help is appreciated. Thanks!

  • Is it an empty array? Update: Instead of echo, try <?php print_r( $item ); ?> to see. May 24, 2012 at 21:53

2 Answers 2


When you set the third parameter of get_post_meta() to false, it returns an array of all the values mapped to that key - setting this parameter to true returns a single value.

So your code is correct. You'd get the exact same thing if you did something like this:

$test = array( "1", "2", "3" );
echo $test; // prints "Array"

If you want to view the contents of your array, you'll need to use print_r():

$item = get_post_meta( $post->ID, 'multiedit_Info', false );
echo print_r( $item );

If you were to do this with the $test array from my above example, you'd see:

    [0] => "1"
    [1] => "2"
    [2] => "3"
  • Ok, if I change it to this: <?php $item = get_post_meta($post->ID, 'multiedit_Info', false); ?> <div id="info-col"> <?php print_r( $item ); ?> </div> It outputs this: Array ( [0] => ) May 24, 2012 at 22:13
  • OK, that means you have an empty array. There is nothing stored in that meta key for that post ID.
    – EAMann
    May 24, 2012 at 22:49
  • So, will this work for ALL the custom fields within the pages or just for that one? I am trying to get ALL or ANY of the custom fields with that meta info. May 24, 2012 at 23:31
  • get_post_meta() only gets meta information for a single post/page. I'm not quite sure what you're trying to accomplish now, and it's not very clear in your question. Can you please edit your question to add some clarification? Don't just list what you've tried, explain in detail what you're trying to accomplish.
    – EAMann
    May 24, 2012 at 23:39
  • Ok, I edited my question. Hopefully that will help a little. May 25, 2012 at 1:05

Ok, I found the solution I was looking for here:

getting all values for a custom field key (cross-post).

By using the function listed in the above post and then calling back the info in my template by using this:

<?php $my_info = get_meta_values( 'multiedit_Info', 'page' ); ?>

and then outputting those in a foreach:

<?php foreach ( $my_var as $item) :
echo "<p>$item</p>";
endforeach; ?>

Grabbed all the custom fields within all of the pages that are using them and then outputted them into a one page.

Thanks for the help!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.