WordPress.org

Ready to get started?Download WordPress

Forums

unable to get id and meta of blog page (8 posts)

  1. rajneeshrana88
    Member
    Posted 2 years ago #

    hi
    i am using get_post_meta($post->ID, 'topheading', true); to get meta fields to show in my theme.
    this works well for all pages except for the blog page.
    i have selected blog page from reading settings and when i goto page this code shows the blog posts meta and not the blog page's meta.
    can anyone help me with this.

    Thanks

  2. s_ha_dum
    Member
    Posted 2 years ago #

    That is how it works in some circumstances.

    Try using $wp_query->queried_object->ID. You may need global $wp_query before that line.

  3. rajneeshrana88
    Member
    Posted 2 years ago #

    hi,
    i tried this but no change. can you help me with anything else that might work for thsi situation?

    Thanks

  4. s_ha_dum
    Member
    Posted 2 years ago #

    I am doing what I think is the same thing. This does work, done right. Post your code to the pastebin please, and provide a link.

  5. rajneeshrana88
    Member
    Posted 2 years ago #

    hi,
    please check this http://pastebin.com/xrD3m5nk
    i am using above code in header.php for showing image and title based on post id.

    Thanks

  6. s_ha_dum
    Member
    Posted 2 years ago #

    Put this at the top:

    global $wp_query;
     $postid=$wp_query->queried_object->ID;
     var_dump(get_post_meta($postid, 'topheading', true));

    What do you get?

  7. rajneeshrana88
    Member
    Posted 2 years ago #

    it shows
    string(17) "IntelliTrack Blog"

    http://seoboony.com/blog.asp this is the page.
    page id is 808

  8. s_ha_dum
    Member
    Posted 2 years ago #

    Is that the result you expected? If it is, then you are getting the post_meta you want, which would mean the problem is elsewhere, maybe with the "if" on line 5 of you pastebin code.

    Interesting that it is an .asp page...

Topic Closed

This topic has been closed to new replies.

About this Topic