codebloo

2 post types, one loop

Dec 23rd, 2016
320
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. <?php
  2. $paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
  3. $custom_args = array(
  4. 'post_type' => array('opinions', 'ideas'),
  5. 'posts_per_page' => 20,
  6. 'paged' => $paged
  7. );
  8. $the_query = new WP_Query( $custom_args ); ?>
  9.  
  10. <?php if ( $the_query->have_posts() ) : ?>
  11.  
  12. <!-- the loop -->
  13. <?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
  14. <?php if ( get_post_type( get_the_ID() ) == 'opinions' ):?>
  15. <?php get_template_part( 'partials/opinions-excerpt' ); ?>
  16. <?php else if ( get_post_type( get_the_ID() ) == 'ideas' ):?>
  17. <?php get_template_part( 'partials/ideas-excerpt' ); ?>
  18. <?php endif;?>
  19. <?php endwhile; ?>
  20. <!-- end of the loop -->
  21.  
  22. <!-- pagination here -->
  23. <?php
  24. if (function_exists(custom_pagination)) {
  25. custom_pagination($the_query->max_num_pages,"",$paged);
  26. }
  27. ?>
  28.  
  29. <?php wp_reset_postdata(); ?>
  30.  
  31. <?php else: ?>
  32. <p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
  33. <?php endif; ?>
Advertisement
Add Comment
Please, Sign In to add comment