Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

The code below writes out a list of the most recent posts. However, it does not appear to be skipping over sticky posts although I'm using 'post_not_in' => get_option('sticky_posts'). What am I missing?

<?php
$cat=get_cat_ID('top-menu'); 
$catHidden=get_cat_ID('hidden');
$myquery = new WP_Query();
$myquery->query(array(
    'cat' => "-$cat,-$catHidden",
    'post_not_in' => get_option('sticky_posts')
));
$myrecentpostscount = $myquery->found_posts;

if ($myrecentpostscount > 0) 
{ ?>
<div><h4>Recent Posts</h4>
<ul>
<?php
global $post;
$current_page_recent = get_post( $current_page );
$myrecentposts = get_posts(array('post_not_in' => get_option('sticky_posts'), 'cat' => "-$cat,-$catHidden",'numberposts' => $cb2_recent_count));
foreach($myrecentposts as  $idxrecent=>$post) {
    ?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php
}
?></ul></div>
share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

You are lacking a one underscore in parameter, it should be post__not_in.

Also the better way is to use caller_get_posts parameter (it will be deprecated and replaced with more aptly named ignore_sticky_posts in 3.1 that will do same thing) that will keep sticky posts in results if they fit, but will prevent them from jumping to the top.

See Sticky Post Parameters in Codex.

share|improve this answer
    
Thanks Rarst! I can't believe it was that easy. –  Scott B Jan 6 '11 at 15:08
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.