Support » Themes and Templates » get_post_meta() in functions.php

Viewing 2 replies - 1 through 2 (of 2 total)
  • have you checked if $post_id is set to the post ID as you might expect?

    in functions.php, it might work using global $post; and $post->ID:

    global $post;
    $desc = get_post_meta($post->ID, 'sandbox_description', true);
    echo '<input type="text" id="myplugin_new_field" name="myplugin_new_field" value="' . $desc . '" size="30" />';

    Thank you! That worked perfectly.

    Would you be able to explain why in this instance I have to get $post_id that way, but when I save it I can do:

    update_post_meta($post_id, 'sandbox_description', $mydata);

    without a problem? I don’t quite understand the difference. I am using a minimally modified version of this example:

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘get_post_meta() in functions.php’ is closed to new replies.