You should just do a new full query for all posts (not just featured ones), and set the orderby
to meta_value
and just check when doing the loop, if that post meta value is yes
, and output the featured template, otherwise output standard one.
https://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters
UPDATE:
Maybe something like this:
$args = array(
'posts_per_page' => - 1,
'meta_key' => 'meta-checkbox',
'orderby' => array( 'meta_value' => 'DESC', 'date' => 'DESC')
);
$posts = new WP_Query( $args );
if($posts->have_posts() ){
while( $posts->have_posts() ){
$posts->the_post();
// Set to content template by default
$template="content";
// Change template to featured when `is_featured` meta has a value
if(get_post_meta(get_the_ID(), 'meta-checkbox', true )){
$template="featured";
}
// Load template part
get_template_part( $template, get_post_format() );
}
}
You will notice I changed the meta key to is_featured
.. it’s good practice to use underscores instead of hyphens.
To get the value for meta on the post, just use the $post
object which has a __get
PHP magic method which will return post meta if it exists.
http://php.net/manual/en/language.oop5.overloading.php#object.get