Based on several different answers, with a SPECIAL thanks to EAMann‘s similar answer – here’s the method I followed.
- Using
new WP_Query
instead ofquery_posts
for this page. - Defining the query variable (
$main_query
) as global. - Querying a temp array (
$temp_featured
) with my featured posts. - Creating an array with only the IDs of the `$temp_featured’. Note EAMann’s use of the wp_list_pluck function.
- Executing the main query of the page (
$main_query
) with the argument to exclude the IDs retrieved in #4.
This is how it came out all in all:
global $main_query;
$temp_featured = get_posts(
array(
'post_type' => 'custom_post',
'custom_post-category' => 'featured-cat',
'posts_per_page' => 2)
);
$featured_ids = wp_list_pluck( $temp_featured, 'ID' );
$query_args = array(
'post_type' => 'custom_post',
'posts_per_page' => $per_page,
'paged' => $current_page,
'post__not_in' => $featured_ids
);
$main_query = new WP_query ($query_args);
//displaying the two featured posts with their own query
$featured = new WP_query( array(
'post_type' => 'custom_post',
'custom_post-category' => 'featured-cat',
'posts_per_page' => 2)
);
while ($featured->have_posts ()) : $featured->the_post();
the_title();
the_excerpt();
endwhile;
//displaying the full query of the page
if ($main_query->have_posts ()) :
while ($main_query->have_posts ()) : $main_query->the_post();
the_title();
the_excerpt();
endwhile;
endif;
I hope this helps anyone – please edit/comment or contact me if you have some further thoughts or inquiries.