Grow your CSS skills. Land your dream job.

WordPress : Help with displaying data from custom meta boxes

  • # August 23, 2012 at 7:54 pm

    I’ve made some custom meta boxes, but I can’t get the info to display outside the loop.
    I’ve tried using this but I get nothing


    global $post;
    $args = array('post_type' =>'post-type');
    $meta = get_post_meta($post->ID, 'meta-box-slug', true);
    wp_reset_query();

    And I’ve tried this too


    global $post;
    $args = array('post_type' => 'post-type');
    $obituary_query = new WP_Query($args);
    while ($obituary_query->have_posts()) : $obituary_query->the_post();
    $meta = get_post_meta($post->ID, 'meta-box-slug', true);
    echo $meta;
    endwhile;
    wp_reset_query();

    That does displays the data but it throws a “Headers already sent error”

    I’m not sure what I’m doing wrong. I haven’t had much luck working with custom meta boxes.

    Thanks in advance.

    # August 23, 2012 at 8:11 pm

    Are you using a plugin?

    # August 23, 2012 at 8:13 pm

    No, but I may just be stupid. I just thought of something. I’ll let you know if it works.

    # August 23, 2012 at 8:24 pm

    OK, yeah I’m stupid. For some reason, I was got it in head that I had to work outside the loop.

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".