WordPress.org

Ready to get started?Download WordPress

Forums

Is "tag__not_in" not working in latest WP? (5 posts)

  1. Matt Hill
    Member
    Posted 4 years ago #

    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?

  2. connorlowe
    Member
    Posted 4 years ago #

    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();
  3. connorlowe
    Member
    Posted 4 years ago #

    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();
  4. rajupp
    Member
    Posted 3 years ago #

    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');
  5. Yaron Guez
    Member
    Posted 3 years ago #


Topic Closed

This topic has been closed to new replies.

About this Topic