Unable to use get_post to display post by ID (3 posts)

  1. Xcellence IT
    Posted 3 years ago #


    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: http://codex.wordpress.org/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.

    $my_id = 7;
    $post_id_7 = get_post($my_id, ARRAY_A);
    $title = $post_id_7['post_title'];
  2. Michael
    Part-Time Forum Moderator
    Posted 3 years ago #

    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.

  3. Xcellence IT
    Posted 3 years ago #

    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?

Topic Closed

This topic has been closed to new replies.

About this Topic