On my index.php file I am showing the most recent posts using the standard index.php file. However, I'd like to include a custom post type (named products) in this standard loop. Have about 6 products posts in total and would like to show them in a random order on the first 12 'slots' of the loop.

So a scenario could be:

1. Product
2. Post (most recent)
3. Post (most recent - 1)
4. Product
5. Post
12. Product/Post
13. Only posts from here on
... Post (oldest)

I have merged the products and posts in the loop as follow:

global $query_string;
parse_str( $query_string, $args );
$args['post_type'] = array( 'post', 'products' );
query_posts( $args );
if (have_posts()) : while (have_posts()) : the_post(); 

Hope this makes sense. Have no clue on how to approach it. Appreciate ideas!


1 Answer 1


This did it:

    $products = get_posts(array('post_type' => 'products'));
    $numbers = range(0, 8); 

    $x = 0;
    foreach($products as $post) : setup_postdata($post);
        $product = new WP_Query(array('p'=>$post->ID,'post_type'=>'products'));
        if (!empty($product->posts)) array_splice($posts,$numbers[$x],0,$product->posts);

    foreach($posts as $post) : setup_postdata($post);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.