Randomly placed sticky custom posts complemented by blog posts

This did it:

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

    $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);
        $x++;
    endforeach;


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

Leave a Comment