WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Custom Field Issue (6 posts)

  1. mitchrenton
    Member
    Posted 5 years ago #

    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?

    Thanks

    Mitch

  2. sojweb
    Member
    Posted 5 years ago #

    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:

    http://codex.wordpress.org/Using_Custom_Fields#Getting_Custom_Fields

  3. mitchrenton
    Member
    Posted 5 years ago #

    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.

  4. sojweb
    Member
    Posted 5 years ago #

    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?

  5. mitchrenton
    Member
    Posted 5 years ago #

    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.

  6. sojweb
    Member
    Posted 5 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic