I did these tree tutorials to create custom metaboxes.

  • wp.tutsplus.com/tutorials/reusable-custom-meta-boxes-part-1-intro-and-basic-fields/
  • wp.tutsplus.com/tutorials/reusable-custom-meta-boxes-part-2-advanced-fields/
  • wp.tutsplus.com/tutorials/reusable-custom-meta-boxes-part-3-extra-fields/

but i don't know how to call values from individual fields. I used this php script

$meta = get_post_meta($post->ID, $field['id'], true);
echo $meta;

but id doesn't work. Does someone know what I do wrong.

here is my function.php http://www.4shared.com/file/8jmKqGFY/functions.html?

and here is my index.php http://www.4shared.com/file/iAWwZim7/index.html?

  • replace $field['id'] with the actual id you gave the field
    – Bainternet
    Mar 2 '12 at 10:06
  • I did this, but it display nothing
    – Itachi
    Mar 2 '12 at 10:12
  • 1
    Can you show us your full loop code?
    – Alex Older
    Mar 2 '12 at 10:56
  • here is my functions.php 4shared.com/file/8jmKqGFY/functions.html? and here is my index.php 4shared.com/file/iAWwZim7/index.html?
    – Itachi
    Mar 4 '12 at 15:08
  • 1
    Are you sure you have the correct meta key? Maybe try print_r( get_post_custom_keys($post_id) ); and you will see all the meta keys associated with that post. (Also for code sharing, I would suggest something like Pastie)
    – Cristian
    Mar 7 '12 at 8:59

After reviewing your code there are a couple of things you need to change depending on where the meta content is being held.

If you try

$meta = get_post_meta( get_the_ID(), 'custom_text', TRUE );
echo 'The meta content is: ' . $meta;`

That should give you the appropriate meta.

You are calling this function on the page content, so unless the meta content is being held there nothing will be output.

Hope that helps!

  • 1
    no it doesn't work but I figured it out :) Solution is this $meta = get_post_meta($post->ID, $field['custom_text'], true); echo $meta[custom_text][0]; Thx for your help
    – Itachi
    Mar 10 '12 at 21:05
  • 2
    Don't for to accept the answer so in the future people know how to get to the solution you did. Also it's polite.
    – Joshua
    May 21 '12 at 2:52
  • Please post your comment as an answer. It helped me a lot! Dec 9 '17 at 12:41

If you're not on a template file where you can't use get_the_ID() (say you're on a plugin file), first get a pointer to the post object associated with the meta content and then use $post->ID.

For example, if you used add_meta_box to define a function displaying the meta box (say display_meta_box), you can retrieve the meta box value thus:

function display_meta_box( $post ) {
  $meta = get_post_meta($post->ID, "meta_key", true); 
  echo "<input name='x' value='$meta' />";

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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