Leave a Reply

2 comments

  1. 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!

  2. 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' />";
    }