Support » Plugin: Custom Post Types and Custom Fields creator - WCK » Display custom field (fieldtype text) in page template out of loop

  • Resolved gskr2014

    (@gskr2014)


    I created a meta box with meta name “testbox” (post type page) and field title “testboxaghg”(field type text).
    I would like to display this box with the following code in my page template outside of the wp-loop. But it doesn’t work. Why the text isn’t displayed?

    <?php $testbox = get_post_meta( $post->ID, 'testbox', true );
    foreach( $testbox as $testboxaghg){
        echo $testboxaghg['testboxaghg'] . '<br/>';
    }?>

    https://wordpress.org/plugins/wck-custom-fields-and-custom-post-types-creator/

Viewing 1 replies (of 1 total)
  • Plugin Author Cristian Antohe

    (@sareiodata)

    If you’re displaying it outsite your loop, $post->ID is probably empty.

    Do a var_dump($post->ID) and see what it returns.

Viewing 1 replies (of 1 total)
  • The topic ‘Display custom field (fieldtype text) in page template out of loop’ is closed to new replies.