Forums

Give help. Get help.

jausions


Forum Replies Created

Viewing 1 post (of 1 total)
  • # September 16, 2012 at 10:18 am

    @ChrisxClash & @roguerocket : `get_post_meta()` doesn’t need to be in the loop, especially when you want the custom fields of the page (i.e. container) itself. The function itself requires a post/page ID (meaning that it doesn’t assume the current post ID, if in the loop).

    If you set the WP home page to be a static page (and therefore also set a separate blog posts page), the solution is to use `get_post_meta( get_option( ‘page_for_posts’ ) );`

    Other functions that might also be useful to you to decide when to use the above:

    – `is_home()`
    – `is_single()`
    – `is_page()`

    All these are handy when you try to customize content in sidebars for instance:

    < ?php
    if ( is_single() || is_page() ) {
    $meta = get_post_meta( get_the_ID() );
    } elseif ( is_home() ) {
    $meta = get_post_meta( get_option( ‘page_for_posts’ ) );
    }
    ?>

Viewing 1 post (of 1 total)
icon-anchoricon-closeicon-emailicon-linkicon-logo-staricon-menuicon-nav-guideicon-searchicon-staricon-tag