• farazch

    (@farazch)


    I created a custom page and below is the code which i used

    <?
    get_header();
    
    $post_id_7 = get_post(15);
    $title = $post_id_7->post_title;
    
    echo "Title : ".$title;
    ?>
    <?
    get_footer();
    ?>

    I want to print tile of post whose id is 15,but instead its showing a blank page.Whats wrong im doing here ?
    Thanks.

Viewing 5 replies - 1 through 5 (of 5 total)
  • vtxyzzy

    (@vtxyzzy)

    If the page is totally blank, the code is not being executed. Otharwise it would show ‘Title: ‘.

    Thread Starter farazch

    (@farazch)

    can u plz tell me why code is not getting executed ? when i disable this code and put any echo statement,it does print tht statement,so control is coming to this page but for some reason it is not extracting the given post details.

    vtxyzzy

    (@vtxyzzy)

    What does this show?

    <?php
    get_header();
    
    echo '<h2>THIS IS A TEST</h2>';
    
    $post_id_7 = get_post(15);
    $title = $post_id_7->post_title;
    
    echo "Title : ".$title;
    ?>
    <?php
    get_footer();
    ?>

    If you don’t see ‘THIS IS A TEST’, either the code is not being called, or something is wrong in get_header().

    Thread Starter farazch

    (@farazch)

    When i comment these two lines

    <?php
    
    $post_id_7 = get_post(15);
    $title = $post_id_7->post_title;
    
    ?>

    then it does print ‘THIS IS A TEST’ as output,so i feel something wrong with these two lines,maybe some global variables r missing.Wat else could b it ?

    vtxyzzy

    (@vtxyzzy)

    I suspect that it is something in the title itself – perhaps some HTML. Try changing this:

    $title = $post_id_7->post_title;

    to this:

    $title = htmlentities($post_id_7->post_title);

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘blank page showing on using method get_post’ is closed to new replies.