WordPress.org

Make WordPress Core

Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#7798 closed defect (bug) (invalid)

tag__not_in doesn't seem to work in filters

Reported by: gmorehoudh Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: General Keywords:
Focuses: Cc:

Description

I'm attempting to exclude posts with a certain tag from feeds under certain conditions. I'm using tag__not_in, but many more posts are disappearing from the feed than are tagged with the particular tag. I've double-checked the tag ID in the database and the manage tags page in the admin interface, so it's not incorrect in my code.

function hide_noaff_posts_from_feed($post) {
	global $query_string;
	if(is_feed()) {
		$vars = parse_str($query_string);
		$vars['tag__not_in'] = array(28);	// 28 is the id of the 'noaff' tag in the terms table
		query_posts($vars);
	}
}

[...]

add_action('loop_start', 'hide_noaff_posts_from_feed');

and

function fff($query) {
	$query->set('tag__not_in', array(28));
	
	return $query;
}

[...]

add_filter('pre_get_posts', 'fff');

Neither of these work properly. They exclude many posts, but I've only tagged one with the tag with id 28.

Change History (7)

comment:1 gmorehoudh6 years ago

This behavior also appears to be happening with categorynot_in.

comment:2 gmorehoudh6 years ago

And also with $query->set('cat', '-29');

The various methods for filtering certain posts based on tag or category appears to be totally broken in 2.6.2. I can't find any other explanation. I've deleted other category-related plugins (that weren't even active) and disabled all my other filter functions, but any time I tell Wordpress, with a filter, to exclude posts in certain categories or with certain tags, it also excludes a bunch of posts that do not meet the criteria.

comment:3 gmorehoudh6 years ago

I've partially figured out what is happening here. Posts aren't actually improperly disappearing. Instead, they are being spit out in an apparently random order, instead of descending by date as they should be. When I scrolled back through all the older entries on the blog's home page, the posts appeared to be all there but completely in the wrong order, both on the main blog and the feed.

comment:4 Otto426 years ago

I'd lay odds that this is the #7226 problem.

comment:5 gmorehoudh6 years ago

We are going to upgrade to 5.0.67 and will report back if this solves the problem.

comment:6 gmorehoudh6 years ago

  • Resolution set to invalid
  • Status changed from new to closed

Upgrading to MySQL 5.0.67 has solved this issue. The posts appearing in semi reversed, semi random order upon attempting to exclude a category or tag is a bug in MySQL, not Wordpress. This was a duplicate of #7226.

See also http://wordpress.org/support/topic/154622?replies=15

comment:7 lloydbudd6 years ago

  • Milestone 2.7 deleted
Note: See TracTickets for help on using tickets.