Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.