Skip to content

Instantly share code, notes, and snippets.

@dospuntocero
Created February 27, 2019 00:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dospuntocero/78b628175acf6e59e34ed87bd686be07 to your computer and use it in GitHub Desktop.
Save dospuntocero/78b628175acf6e59e34ed87bd686be07 to your computer and use it in GitHub Desktop.
Query multiple custom post types in single loop
<?php
$args = array(
'post_type' => array('testimonial', 'other_post_type', 'another-post-type'),
'posts_per_page' => 1,
'tax_query' => array(
array (
'taxonomy' => 'testimonial_category',
'field' => 'slug',
'terms' => 'home'
)
)
);
$query = new WP_Query( $args );
$postcount = 0;
?>
<?php if ($query->have_posts()) : ?>
<?php while ($query->have_posts()) : $query->the_post(); ?>
<?php $postcount++; ?>
//loop here
<?php wp_reset_query(); ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment