Order posts using ACF checkbox and custom post type
-
Working on listing my custom post type by act meta value (current/previous), but have a question regarding the simplest way to do it. Right now I have the following code which seems like overkill. I’m sure there is a simpler way to doing this so I’m not duplicating code. Could I use something that would translate to the effect of “if current, list first” so I didn’t have to query the custom post type twice? Teaching myself all this so want to find out the best and most efficient ways to do all things PHP.
<?php
$paged = (get_query_var(‘paged’)) ? get_query_var(‘paged’) : 1;
$args = array(
‘post_type’ => ‘people’,
‘meta_key’ => ‘student_status’,
‘meta_value’ => ‘current’
‘order’ => ‘ASC’,
‘paged’ => $paged,
‘posts_per_page’ => 10
);$the_query = new WP_Query( $args );
while ( $the_query->have_posts() ) : $the_query->the_post();
?><div class=”post”>
<?php if(get_field(‘photo’)):?>
<div class=”photo”><img src=”<?php the_field(‘photo’); ?>” /></div>
<?php endif; ?>
<p>“><?php the_title(); ?>
<?php if(get_field(‘contact_info’)):?>
<?php the_field(‘contact_info’); ?></p>
<?php endif; ?>
<?php if(get_field(‘cv’)):?>
<p>“>Download CV »</p>
<?php endif; ?><?php the_excerpt(__(‘(more…)’)); ?>
<!–<div class=”keepreading”><p>“>Keep Reading »</p></div>–>
</div>
<?php
endwhile;
wp_pagenavi( array( ‘query’ => $the_query ) );
wp_reset_postdata();
?><?php
$paged = (get_query_var(‘paged’)) ? get_query_var(‘paged’) : 1;
$args = array(
‘post_type’ => ‘people’,
‘meta_key’ => ‘student_status’,
‘meta_value’ => ‘previous’
‘order’ => ‘ASC’,
‘paged’ => $paged,
‘posts_per_page’ => 10
);$the_query = new WP_Query( $args );
while ( $the_query->have_posts() ) : $the_query->the_post();
?><div class=”post”>
<?php if(get_field(‘photo’)):?>
<div class=”photo”><img src=”<?php the_field(‘photo’); ?>” /></div>
<?php endif; ?>
<p>“><?php the_title(); ?>
<?php if(get_field(‘contact_info’)):?>
<?php the_field(‘contact_info’); ?></p>
<?php endif; ?>
<?php if(get_field(‘cv’)):?>
<p>“>Download CV »</p>
<?php endif; ?><?php the_excerpt(__(‘(more…)’)); ?>
<!–<div class=”keepreading”><p>“>Keep Reading »</p></div>–>
</div>
<?php
endwhile;
wp_pagenavi( array( ‘query’ => $the_query ) );
wp_reset_postdata();
?>
The topic ‘Order posts using ACF checkbox and custom post type’ is closed to new replies.