• I thought this code should work but it doesn’t display either the post title or the contents. (I am using the Executable php widget to display content of a post in the sidebar)

    <?php
    $my_id = 324;
    $post_id_324 = get_post($my_id);
    $title = $post_id_324->post_title;
    $content =$post_id_324->post_content;
    echo($title);
    echo($content);
    ?>

Viewing 1 replies (of 1 total)
  • Thread Starter andy3000

    (@andy3000)

    I switched to this. It displays the post title but no contents.

    <?php
    $page_id = 324; // 123 should be replaced with a specific Page's id from your site, which you can find by mousing over the link to edit that Page on the Manage Pages admin page. The id will be embedded in the query string of the URL, e.g. page.php?action=edit&post=123.
    
    $page_data = get_page( $page_id ); // You must pass in a variable to the get_page function. If you pass in a value (e.g. get_page ( 123 ); ), WordPress will generate an error. By default, this will return an object.
    
    echo '<h3>'. $page_data->post_title .'</h3>';
    echo apply_filters('the_content', $page_data->post_content); // echo the content and retain WordPress filters such as paragraph tags.
    ?>

Viewing 1 replies (of 1 total)
  • The topic ‘Function to display title and content of another post’ is closed to new replies.