WordPress.org

Ready to get started?Download WordPress

Forums

Order posts using ACF checkbox and custom post type (1 post)

  1. rippkedesign
    Member
    Posted 4 months ago #

    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();
    ?>

Reply

You must log in to post.

About this Topic