I’m using the get_post_meta function to call and echo custom fields used on ‘Pages’ with a WP site. However, on the ‘Blog’ page this method is not working. I’m guessing that it’s because it’s not a ‘page’ but a group of posts.
Does anyone have any suggestions on how to call and echo these custom fields on the the ‘blog’ page as well as the single and archived pages for blog posts? Below is the code I’m using in the ‘header’.
@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:
All these are handy when you try to customize content in sidebars for instance: