Support » Fixing WordPress » Custom Field Issue

  • Resolved mitchrenton


    I am using custom fields to display some text in my header using…

    <?php echo get_post_meta($post->ID, ‘intro’, true); ?>

    The text displays on all of my pages except the blog page. Is there any reason the blog page should prevent the text from been displayed?



Viewing 5 replies - 1 through 5 (of 5 total)
  • By blog page, you mean the page listing multiple posts? The function is probably not being used in the Loop, and $post isn’t referring to what you think it is. Take a look here, if you haven’t already:

    Yes i mean the page displaying my posts. My code isn’t in the loop but I didn’t think it had to be? I have looked at the page you suggested but still cant see a remedy. So what is $post referring to? I thought it was referring to all posts.

    Well, in the Loop, $post refers to whichever individual post is being output at the moment. If you’re using it outside the loop on an archive page, it’s probably referring to the first post that’s being listed, which, in your case, may not have that custom field set. To make matters more fun, every time you add a post, $post will refer to something else.

    What is it you’re trying to do with the custom field?

    I’m just using the custom field in my pages to display some text in the header, different text for each page. I just find it strange that the custom field works as i intended on every page except my blog page, which must be what your saying. So is there some modification I can make to the code i was using? Would really appreciate some help on this one.

    Well, you’re blog page is listing multiple pages, so there’s no way for it to know which text you want to use. You could just stick some text in the template file.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Custom Field Issue’ is closed to new replies.