July 24, 2014 by Nitesh

How To Get All Posts From Multiple Post Types in WordPress


In our last post, we saw how can we get all posts from a specific custom post type in WordPress. This post explains how can you get all posts form multiple post types in WordPress. Let us assume, we have 3 different post types named “cats”,”dogs’ and “rats” and we want to display all published posts that are under any of these 3 categories.

To do this, we will use the following code –

     $args = array( 
	 'post_type' =>	array( 'cats', 'dogs', 'rats'),
         'post_status'		=>	'publish'
	$the_query = new WP_Query( $args );

The above code creates an array and passes an array of all post types that we want to query for. Then we query WordPress using the defined set of parameters and it returns us all posts under this category.

Hope this helps you! Keep learning and sharing! Cheers!

#Custom Post Types#PhP#WordPress
  • Alseiff

    Thank you so much, i needed this line: ‘post_type’ => array( ‘cats’, ‘dogs’, ‘rats’),

Support us!

If you like this site please help and make click on any of these buttons!

Powered by WordPress Popup