How to get custom fields from get_post using single page?

I have a news page where it display all the news and there is a read more button with a permalink function. When it is clicked it will redirect the user into single page news for more information although I can’t query the custom fields.

post type: news
meta: news

Read More

Thank you in advance!

anyway here is my code

$post_id = get_the_ID();
$queried_post = get_post($post_id);
$test = get_custom_field('picture-description', TRUE);
$title = $queried_post->post_title;
echo $title;
echo '<br/>';
echo $test;
echo $queried_post->post_content;

Related posts

Leave a Reply

1 comment

  1. Here are some things you can try:

    Make sure your stuff is in a post loop

    http://codex.wordpress.org/The_Loop

    <?php 
    if ( have_posts() ) {
        while ( have_posts() ) {           
           $test = get_custom_field('picture-description', TRUE);
           the_title();
           echo '<br/>';
           the_content();
        } // end while
    } // end if
    ?>
    

    Try an alternative function

    http://codex.wordpress.org/Function_Reference/get_post_meta

    get_post_meta($post_id, 'picture-description', TRUE);
    

    Ensure you are in the right file.

    For a post single the naming convention of the file should be
    something like single.php or single-posttype.php

    enter image description here

    Let me know if any of these things work.