Skip to main content
3 of 5
added 786 characters in body

How to query custom post then display sections by meta value

This seems like an easy thing to do but I am missing something here. I have a custom post type called "recipient" and a meta check box called "yes_current" - (we help children with cancer and run events for them so we need to know who is a current recipient and who is a past recipient.) We want to display two sections on our RECIPIENT page: CURRENT RECIPIENTS and PAST RECIPIENTS.

My thought is to query the loop to get all of the custom_post_types that equal recipient, then display the featured image for all CURRENT recipients (if yes_current is ON) in the Current section, then do the same for PAST recipients in the Past section.

Thank you guys!

CODE:

<h1>CURRENT Recipients</h1>

<?php $current_loop = new WP_Query(array('post_type' => 'recipient', 'posts_per_page' => '-1', 'yes_current' => 'on'));

if( $current_loop->have_posts() ): while( $current_loop->have_posts() ): $current_loop-the_post(); 

<?php get_the_post_thumbnail($linkvalue, 'thumbnail'); ?>

<?php endwhile; endif; wp_reset_postdata(); ?>

<h1>PAST Recipients</h1>

<?php $current_loop = new WP_Query(array('post_type' => 'recipient', 'posts_per_page' => '-1', 'yes_current' => 'off'));

if( $current_loop->have_posts() ): while( $current_loop->have_posts() ): $current_loop->the_post(); 

<?php get_the_post_thumbnail($linkvalue, 'thumbnail'); ?>

<?php endwhile; endif; wp_reset_postdata(); ?>