• Hi,

    On home page I want to display a post (by ID – given by admin as theme option) with its title, excerpt & featured image. I have tried it with a function get_post, but it doesn’t seem to work. At first it gives Fatal Error, but then after figuring out that it needs variable as an ID, its solved. But still I’m unable to get the information I need there on home page (front-page.php template).

    Referring to this: https://codex.www.ads-software.com/Function_Reference/get_post

    I have this should display a title of the post with ID = 7. But it doesn’t can anybody figure out how to use this for my purpose? I also need featured-image & excerpt.

    <?php
    $my_id = 7;
    $post_id_7 = get_post($my_id, ARRAY_A);
    $title = $post_id_7['post_title'];
    ?>
Viewing 2 replies - 1 through 2 (of 2 total)
  • this should display a title of the post with ID = 7

    the posted code assigns the value of the post title to the variable $title, but there is no ‘display’ code such as echo or print_r in your code.

    Thread Starter Xcellence IT

    (@xcellenceit)

    Hey, Why can’t I noticed that.. Sorry.

    I’m now able to get title and content. But still excerpt, and featured image is not fetched. Any idea can I easily get it with this… can you help with code snippet to get the same?

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Unable to use get_post to display post by ID’ is closed to new replies.