0

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>

1 Answer 1

1

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.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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