By default WP_Query
will return only the post
post type. To retrieve other post types, you need to add a post_type
argument. Using any
will return results from all public, registered post types.
$my_query = new WP_Query(
array(
'cat' => 1,
'post_type' => 'any'
)
);
var_dump($my_query->request); // debug; allows you to see the SQL
if($my_query->have_posts()) {
// ..
}
If you only want a particular post type, just use the post type’s slug, or you can use an array of post type slugs to get returns from multiple particular post types.
Also, there is rarely a good reason to clobber $wp_query
, even if you save it to put it back later.