• Resolved stonedeft

    (@stonedeft)


    Hello forums

    How do you get the post meta using the query_post function

    I have this:

    query_posts('category_name=videos');
     while (have_posts()) : the_post();
     echo get_post_meta($post->ID, 'videoThumb', true);
     endwhile;

    Somehow it isn’t working

    when I tried to echo $post->ID there is no value but when I echoed the_title() there is a value. I think the post id is NULL.

    Thanks

Viewing 2 replies - 1 through 2 (of 2 total)
  • Looks okay so would guess the category_name is failing or ‘videoThumb’ is failing.

    Thread Starter stonedeft

    (@stonedeft)

    Since I am using this code inside a plug-in file I should globalize $post so I can get the value of $post->ID

    <php?
    query_posts('category_name=videos');
     while (have_posts()) : the_post();
     echo get_post_meta($post->ID, 'videoThumb', true);
     endwhile; ?>

    other way to do it is with wp_query

    <?php
    $my_query = new WP_Query(‘cat=4’);
    while ($my_query->have_posts()) : $my_query->the_post();
    global $post;
    echo get_post_meta($post->ID, ‘videoThumb’, true);
    endwhile; ?>

    Cheers!!

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘get_post_meta with query_post function’ is closed to new replies.