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; ?>
</div>
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!
When you set the third parameter of
get_post_meta()
tofalse
, it returns an array of all the values mapped to that key – setting this parameter totrue
returns a single value.So your code is correct. You’d get the exact same thing if you did something like this:
If you want to view the contents of your array, you’ll need to use
print_r()
:If you were to do this with the
$test
array from my above example, you’d see: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:
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!