• Resolved Ben Kaeding

    (@benkaeding)


    I’m pretty sure that I have a syntax error or two preventing this from working as expected.

    <?php echo get_the_post_thumbnail('. $query_posts('meta_key=PVC_Featured_Image&meta_value=1');
    if (have_posts()) :
        while (have_posts()) : the_post();
            $str = get_the_ID() ;
            echo $str;
        endwhile;
    else :
        echo 'Something else happens here';
    endif; .'); ?>
Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator keesiemeijer

    (@keesiemeijer)

    Hi, Ben Kaeding

    What is it you want to do? And on what page are you trying to do this?

    if you are trying to get the ID if a post (or several posts?) (based on some query parameters) into the post thumbnail function and show the thumnail,
    then try to re-assemble your code into something like:

    <?php $my_query = new WP_Query('meta_key=PVC_Featured_Image&meta_value=1');
    if ($my_query->have_posts()) :
        while ($my_query->have_posts()) : $my_query->the_post();
            $str = get_the_ID() ;
            echo get_the_post_thumbnail( $str );
        endwhile;
    else :
        echo 'Something else happens here';
    endif; wp_reset_postdata(); ?>
    Thread Starter Ben Kaeding

    (@benkaeding)

    alchymyth, That is almost exactly what I needed. I added the post _type to include both pages and posts.

    <?php $my_query = new WP_Query('meta_key=PVC_Featured_Image&meta_value=1&post_type=any');

    I should have know that. Thanks for your assistance.

    Thread Starter Ben Kaeding

    (@benkaeding)

    Resolved.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Return Post ID using query for meta_key and meta_value within an echo’ is closed to new replies.