You shouldn’t use query_posts for multiple queries.
Show featured posts by…
<?php $args = array(
'featured' => 'yes'
);
$featured = new WP_Query($args);
if($featured->have_posts()): while($featured->have_posts()): $featured->the_post();?>
Featured posts stuff...
<?php endwhile; endif; wp_reset_postdata();?>
Then show regular posts by…
<?php if ( have_posts() ) : while ( have_posts() ) : the_post();?>
Post content...
<?php endwhile; endif; ?>
Thanks, but the thing I want is show all the NON-featured posts, do you know how to do that ? featured => no doesn’t work
Hi Matthieu,
I am newbie in WP but i had the some problem and locked into the plugin code. I have changed pre_get_posts function and worked for me. Hope this can help.
ps. Sovit thanks for your plugin – it’s very intuitive for the End user
function pre_get_posts( $query )
{
if ( !is_admin() ) {
if ( $query->get( 'featured' ) == 'yes' ) {
$query->set( 'meta_key', 'featured' );
$query->set( 'meta_value', 'yes' );
}
else if ( $query->get( 'featured' ) == 'no' ) {
$metaquery = array(
'relation' => 'OR',
array(
'key' => 'featured',
'value' => 'yes',
'compare' => '!='
),
array(
'key' => 'featured',
'value' => '',
'compare' => 'NOT EXISTS'
)
);
$query->set( 'meta_query', $metaquery );
}
}
return $query;
}
UPDATE:You should also update the admin_ajax function. Please see below
function admin_ajax( )
{
$post_id = $_POST[ 'post_id' ];
$is_featured = get_post_meta( $post_id, 'featured', true );
$newStatus = $is_featured == 'yes' ? 'no' : 'yes';
delete_post_meta( $post_id, 'featured' );
if ($newStatus=="yes")
add_post_meta( $post_id, 'featured', $newStatus );
echo ":P";
die( );
}