• I can’t seem to get “tag__not_in” to work, is it confirmed as working in 2.8.6? The following query still returns posts that have the tag I’m trying to exclude:

    <ul>
    <?php
    global $schoolCats;
    $schools_parent = 26;
    $args=array(
    'posts_per_page'=> 2,
    'cat'=> $schoolCats,
    'tag__not_in'=> array(28),
    );
    
    $schoolPosts = new WP_Query($args);
    while ($schoolPosts->have_posts()) : $schoolPosts->the_post();
    	setup_postdata($post);
    	$cats = get_the_category();
    	$school = "";
    	foreach($cats as $category)
    		{
    		if ($category->category_parent == $schools_parent){
    		$school .= $category->cat_name;
    		}
    	}
     ?>
    <li>
    <a href="<?php the_permalink();?>"><?php the_title(); ?></a><br /><strong><?php echo $school; ?></strong><br />
    <?php the_excerpt(); ?>
    </li>
    <?php endwhile; ?>
    </ul>

    Basically, this is just a loop to display a bunch of posts that aren’t tagged with the tag “resource” (tag ID = 28). I have no idea why it’s not working, I’d be very grateful of any ideas?

Viewing 4 replies - 1 through 4 (of 4 total)
  • I am also having this problem. I am curious if it has to do with using the WP_Query object, as I also am.

    $slug = basename(get_permalink());
    
    $activeProjects = new WP_Query();
    $activeProjects->query('tag__not_in=57&category_name='.$slug); 
    
    if($activeProjects->have_posts()) : while($activeProjects->have_posts()) : $activeProjects->the_post();

    It must have been bad syntax. This got it working:

    $args=array(
    	'cat'=> '54',
    	'tag__not_in' => array('57')
    );
    
    $activeProjects = new WP_Query();
    $activeProjects->query($args); 
    
    if($activeProjects->have_posts()) : while($activeProjects->have_posts()) : $activeProjects->the_post();

    I am having the same problem as gambit37 with tag__not_in. I was trying to exclude posts with a particular tag from the feed, but it just doesn’t seem to work

    function exclude_tag($query) {
    if ( $query->is_feed) {
    	$query-> set('tag__not_in',array(9278));
    	}
    return $query;
    }
    add_filter('pre_get_posts','exclude_tag');

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Is “tag__not_in” not working in latest WP?’ is closed to new replies.