Query custom post types and a specific page?

I’m using this query WP_Query('post_type=product&posts_per_page=8') I need to include a specific page into the query but not sure how to add it since I’m only specifying the custom post type? Is it possible to add in a page?

Related posts

Leave a Reply

1 comment

  1. If I understand you correctly you want a bunch of posts from a custom post type and in some way combine it with a page. To do this you would first have to get the queried objects:

    $page_id = 123; // the id of the page you want to retrieve
    $cpt_objects = new WP_Query( array( 
      'post_type'        => 'product',
      'posts_per_page'   => 8
      ));
    $page_object = new WP_Query( array( 
      'post_type'        => 'page',
      'page_id'          => $page_id
      ));
    

    Now you can loop through the $cpt_objects and insert the $page_object anywhere you like.