• I must be missing something really obvious here, but I just can’t seem to get it.

    I’m trying to add some meta data (entered via a custom field named ‘offers’) to the header of my page.

    I suspect that the code I need is:
    $offers = get_post_meta($post->ID, 'offers', TRUE);

    The problem that I have with this is I need to be inside ‘the loop’ to use $post->ID don’t I? My header appears before the main loop begins, so I have a bit of a problem.

    I’ve seen that maybe multiple loops is the way to go, is that correct?

    Regards
    Rich

Viewing 1 replies (of 1 total)
  • Hi,

    I tried to do the same with my blog and WP2.7.1, and it works, even just after the <head> tag, so outside the loop, I added this test:

    if ( is_single() ) {
    echo get_post_meta($post->ID, 'nom_plugin', true);
    }

    are you sure that you named the field offers?

    did you try on a post that have a value for this key?

    when you say header, is it inside the <body> ?

    maybe something changed the $post, you can get it again with wp_query:

    if ( is_single() ) {
    global $wp_query;
    $post = $wp_query->post;
    echo get_post_meta($post->ID, 'nom_plugin', true);
    }
Viewing 1 replies (of 1 total)
  • The topic ‘Using meta data outside of the main loop’ is closed to new replies.