WordPress WP_Query call posts AND pages

I have a feature slider set up that draws in posts that are tagged ‘feature’

$my_query = new WP_Query(array(
  'showposts' => 3,
  'tag'  => 'feature' ));

Is is possible to draw in posts AND pages?
I know you can draw pages with 'post_type'=>'page' but can you mix the two?

Related posts

Leave a Reply

3 comments

  1. You can specify an array value for the post_type parameter, as such:

    $my_query = new WP_Query(array(
        'post_type' => array('post', 'page'),
        'tag'  => 'feature'
    ));
    

    See this page for more info: WP Codex

  2. For anyone having to edit older code that doesn’t use an array passed into WP_Query, you can add &post_type=any to get posts and pages (and other content). Unfortunately I don’t see a way to get posts and pages (without other types) without using an array, since post_type would then require an array as the examples above show. However, this should be good enough if you are searching for a particular category anyway.

    Example (this from vSlider v4.1.2 where &post_type=any is added so that pages are included in the slider):

    $recent = new WP_Query($randimg."cat=".$options['imgCat']."&showposts=".$options['slideNr']."&post_type=any");
    

    Thanks to @fivedigit and @my-jonny-wood for the answers above that led me to figuring this out and fixing the slider on my site!