0
votes

I have a loop with excluded category (Featured) so now my category is not visible inside the loop.
Now here is my problem if I set my post inside Featured category to be "sticky" that post will still show up inside my loop.
What I would like to accomplish is to hide that category sticky posts (Featured), but allow my other posts (From other categories) to be "sticky".
My Loop:

<?php 
    $category = get_cat_ID('Featured');//Get our Featured Category     
    $args = array(           
    'category__not_in' => $category //Category is excluded 
                                   // but 'sticky' ones from Featured category
                                  // are still showing up...         
);

$temp = $wp_query;
$wp_query = null;
$wp_query = new WP_Query($args);

if($wp_query->have_posts()):?><?php while ( $wp_query->have_posts() ) : $wp_query->the_post();?>

    <div <?php post_class(); ?> id="post-<?php the_ID(); ?>">

        <div class="entry"> 

            <?php the_content(__('Read more','my-domain')); ?>  

        </div><!--/entry-->
    </div><!--/post_class-->        
    <?php endwhile; ?>  
    <?php endif; ?><!--END if THE LOOP-->
<?php
$wp_query = null;
$wp_query = $temp;
wp_reset_query();
?>

Any thoughts how can I solve this problem?

1

1 Answers

2
votes

I don't have a test system available, but according to the Codex, something like this should work:

$sticky = get_option( 'sticky_posts' );
$args = array(
    'category__not_in' => $category,
    'ignore_sticky_posts' => 1,
    'post__not_in' => $sticky
);
$query = new WP_Query( $args );