I'm attempting to do this but with multiple posts and specific positions. The post positions are hard coded right now, but will be pulled in from post meta. This code is only being ran on the homepage and the posts aren't paginated.
$essay_args = array(
'posts_per_page' => get_option('posts_per_page'),
'post__not_in' => array($post->ID),
'post_type' => array('post')
);
$essays = get_posts( $essay_args );
$fixed_posts = get_posts(array('post_type'=>array('ad','book')));
$positions = array(2,5,10); // to be pulled in from ad/book posts
$x = 0;
foreach($fixed_posts as $fixed_post) : setup_postdata($post);
$e_posts = new WP_Query(array('p'=>$fixed_post->ID,'post_type'=>array('ad','book')));
if (!empty($e_posts->posts)) array_splice($essays,$positions[$x],0,$e_posts->posts);
$x++;
endforeach;
foreach($essays as $essay) : setup_postdata($post);
echo $essay->post_title . '<br>';
endforeach;
Does it make more sense to do multiple WP_Query/get_posts requests for each post by id or does that tax the database too much? Is a there a cleaner way to do this?
$fixed_posts
, why are you querying them one by one again withWP_Query
?$fixed_posts
?