Support » Fixing WordPress » get_post_meta on homepage

Viewing 11 replies - 1 through 11 (of 11 total)
  • Is your homepage a page?

    If so, try using is_page(‘home’) instead of is_home().

    esmi

    (@esmi)

    Forum Moderator

    Firefox can’t find the server at http://www.signyourbkeout.com.

    esmi there is an ‘i’ missing from the link:

    http://www.signyourbikeout.com

    Paul Wright

    (@signyourbikeout)

    Hello,

    Thanks for the reply, but no, I’m using the hierarchy and a home.php template. I inserted your code anyway, but to no avail.

    Paul Wright

    (@signyourbikeout)

    Yep, sorry, fixed the URL

    esmi

    (@esmi)

    Forum Moderator

    I’m using the hierarchy and a home.php template.

    Get rid of home.php. It creates nothing but trouble on most sites. Stick with index.php or a custom page template for a static front page if necessary called something like homepage.php or – even better – front-page.php.

    Paul Wright

    (@signyourbikeout)

    Ok, I will try front-page.php on that suggestion and switch the home to a static page.

    What’s the recommended use case for home.php?

    esmi

    (@esmi)

    Forum Moderator

    In my experience, don’t use it. It’s an old hackish way of having a custom front page and it just isn’t needed any longer. However, it can cause issues/confusion in some cases – just like this one, in fact – because you’re relying on the servers directory index order rather than WP’s template hierarchy

    Paul Wright

    (@signyourbikeout)

    So in order to do this correctly, I have to create a physical page for home? I guess that is what I was trying to avoid.

    I’ve switched home.php to front-page.php and it doesn’t help, next step would be to create a real page for home and set it as the static home page in settings and select a page template in the page screen. Is that the only way? I was hoping to not have a ‘real’ page for home for some reason.

    Paul Wright

    (@signyourbikeout)

    Hmm, this goes a bit deeper I think.

    After changing to page-home.php (which correctly gets called), it still doesn’t retrieve the meta boxes. And now, the meta boxes I call in my header don’t work for the home either. This was working fine on home (and still does for single)

    [Code moderated as per the Forum Rules. Please use the pastebin]

    I also tried a global $post in there, but it didn’t help

    Hi, I had the same problem when calling get_post_meta from home.php and I was able to fix it. I found the answer here (Katie).

    I quote:

    If you are calling get_post_meta inside the loop then you should call get_post_meta(get_the_id(), ‘YOURKEY’, true) instead of get_post_meta($post->ID, ‘YOURKEY’, true)

    Strange things happens when you call get_post_meta inside a loop. In some themes developers hack the $post at the beginning and get_post_meta stops working so this is one of the solution for those particular cases too.

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘get_post_meta on homepage’ is closed to new replies.