Just found a weird effect on a lage site I manage. I recently upgraded to 2.3.1 and have not implemented tags on the site, but users have started to tag articles.
The site, http://www.3ammagazine.com/3am/, is organised by categories, and each article is in only one category. However, we’ve discovered that if an article is tagged with the name of a category, it appears in this category too.
e.g. an article in the Interviews category (cat 2) is tagged (among other things) ‘fiction’. However, when the latest Fiction category articles are called with
$myposts = get_posts('numberposts=3&category=5');
the article is called by $myposts here too.
Why is this happening, is it intended, and if so, why? I’m sure tags and categories are meant to be different systems.
It is not intended. Looks like get_posts() is a bit buggy here. I’ll report it, but for now there’s two options to get around the bug:
1. Follow the examples here:
for using query_posts() or the WP_Query() class to set up your category loops.
2. Fix the bug!
If you’re up to editing the WordPress core, get_posts() is defined in wp-includes/post.php. At or around line 257 in post.php you’ll find this line:
$query .= empty( $category ) ? '' : "AND ($wpdb->posts.ID = $wpdb->term_relationships.object_id AND $wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id AND $wpdb->term_taxonomy.term_id = " . $category. ") ";
Change it to the following:
$query .= empty( $category ) ? '' : "AND ($wpdb->posts.ID = $wpdb->term_relationships.object_id AND $wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id AND $wpdb->term_taxonomy.term_id = " . $category. " AND $wpdb->term_taxonomy.taxonomy = 'category') ";
Source editing note: Back up files before editing.
EDIT: Already reported – http://trac.wordpress.org/ticket/5317
Good to know, and thanks for the info. I’m not going to edit the core, but this seems like a pretty serious thing to me, and I’m surprised it’s possible to confuse tags and categories this easily… it suggests all the implications of adding tags to WP haven’t been fully thought out.
(I speak as a massive WP fan…)
stml, no matter how well thought out anything regarding software is, bugs will creep in. It doesn’t matter how good the developers are, or how much pre-testing is done on the various parts of an application. Bugs will show up.
I put in that ‘massive WP fan’ comment to deflect those replies! I’m aware bugs will creep in – what I’m saying is that I’m surprised that tags were implemented in a way that this could happen. It’s criticism, not an attack.
Have joined wp-testers as I implement on average a couple of WP installs a month, and do want to give something back…
- The topic ‘Tags being used as categories by WP’ is closed to new replies.