tags:

views:

81

answers:

4

The script below should be exluding items that are assigned to the "my-menu" category. However, they are still showing up. Can someone help me identify the logic flaw?

<?php 
global $post; 
$cat=get_cat_ID('my-menu'); 
$catHidden=get_cat_ID('hidden'); 
$count=0; 
$myposts2=get_posts(array('post__not_in'=>get_option('sticky_posts'),'cat'=>-$cat,'cat'=>-$catHidden,'showposts'=>5)); 
foreach($myposts2 as $post) : 
    $count++; 
    ?><li><a href="<?php 
    the_permalink(); 
    ?>"><?php 
    the_title(); 
    ?></a></li><?php 
endforeach; 
?>
A: 

Two guesses:

  1. post__not_in looks wrong - should it be a double underscore?
  2. Assuming this is wordpress, I can't see a 'post_not_in' parameter on the get_posts page of the codex
adam
+1  A: 

From the codex:

Multiple category IDs can be specified by separating the category IDs with commas

So you want:

$myposts2 = get_posts(
    array(
        'post__not_in' => get_option('sticky_posts'),
        'cat' => "-$cat,-$catHidden",
        'showposts' => 5
    )
);
adam
Bingo! Thanks a ton Adam! I've selected your answer and tested it works perfectly.
Scott B
+1  A: 

'cat'=>-$cat,'cat'=>-$catHidden, looks wrong to me. Assigning multiple values to same variable?

Amarghosh
+1  A: 

I believe you can modify it like so to work:

change the snippet:

'cat'=>-$cat,'cat'=>-$catHidden,

to:

'category__not_in' => array( $cat, $catHidden ),
James Maroney