Downloads: TDO Tag Fixes WordPress Plugin (0.5)
Download now from WordPress.org!
Requires at least WordPress v2.3 and tested up to WordPress v2.5.1.
This plugin is simply intended as an example of how to implement tag and category intersections. However it has got a bit more feature-heavy recently. Please feel free to re-use the code in your plugin. This plugin is based on information found here.
Version 0.5 enables true 'or' tag intersection when using a category. It wasn't working prior to this (and no-one noticed). Thanks to Joel Giddey for spotting it.
Wordpress 2.3 introduced native tagging support, which is rather nifty.
But did you know that you can display multiple tags in the one archive and even generate a feed for that?
- "
http://your-blog-uri/?tag=tag1,tag2" this would get all the posts tagged with tag1 or tag2. - "
http://your-blog-uri/?tag=tag1+tag2" this would get all the posts tagged with tag1 and tag2 - "
http://your-blog-uri/?tag=tag1,tag2&feed=rss" this would get you an RSS feed for all the posts tagged with tag1 or tag2
Neat huh? But did you notice that on the generated tag page you see only one tag listed in the header? This function fixes that and displays all tags used to generate that tag archive. It does this by silently modifying the single_tag_title template tag. It'll even work on the RSS feed generated by that page!
What would be also be cool is to be able to intersect categories and tags so you could grab posts with tags from a specific category for example?
With this plugin you can. It's not perfect however. It only allows intersection between a single category and one or more tags. Technically Wordpress should be able to support multiple categories and tags intersections but it didn't work for me in Wordpress 2.3.x and 2.5.
So go to one of your category pages. If your using using fancy permalinks then at the end of the url add "?tdo_tag=a_tag". If your not using permalinks then you can just use "&tdo_tag=a_tag". You must use the tag slug, not the full tag name. You can use multiple tags as above using "," and "+".
- Example not using fancy permalinks: "
http://your-blog-uri/?cat=35&tdo_tag=tag1,tag2" this would get all posts in category with id 35 and tagged with either tag1 or tag2. - Example using fancy permalinks: "
http://your-blog-uri/category/mycategory/?tdo_tag=tag1+tag2" this would get all posts in the category "mycategory" and tagged with both tag1 and tag2.
This plugin uses this intersection code to automatically modify the built-in tag cloud template tag wp_tag_cloud so that if it is used on a category archive, it shows only the tags within that category. You can then click on a tag in that tag cloud and it will get the posts for in that category that tagged with that tag. (You can disable this and just use the specific template as you need).
This plugin has been downloaded 2,590 times.
Guest
April 21st, 2008 at 2:31 pm
putting this plugin into mu-plugins directory gets me a blank screen (nothing shows up), unplugged it and back to normal again.. (for a second my heart stopped beating.. lol)
Guest
April 24th, 2008 at 4:05 am
hi mark .thanks of course
to fix the (tdof_)the_tags() on is_single() pages, i added this to your tdof_the_tags()
function tdof_the_tags( $before = '', $sep = '', $after = '' ) {
global $tdotf_tag_get_var,$cat;
// mr.snow - we need to get the category another way if !is_category()
if ( ! $cat ) {
$category = get_the_category();
$cat = $category[0]->cat_ID;
}
// if(is_category() && isset($tdotf_tag_get_var)) {
if(isset($cat) && isset($tdotf_tag_get_var)) {
…
Administrator
April 24th, 2008 at 9:24 am
Thanks Queenvictoria,
I was a bit unsure if it made sense to have it point to the category+tag when your on a single page. What happens if you have multiple categories for a post? You’ll only get the 1st category!
I’ll see about rolling in the chance with some additional enhancements (like allow the user to specify what category to use)
Guest
May 13th, 2008 at 4:11 pm
hi. Thanks for plugin
perfect.
regards
Guest
June 3rd, 2008 at 3:24 am
Hi, it’s me again. I still can’t get the category/tag intersection to work. I’m now using WP 2.5.1, TDO Tag Fixes .4, and SimpleTags 1.5.7 (plus a few non-tag related plugins). Here is an example link:
http://philip.yurchuk.com/category/software/?tdo_tag=rhino
You’ll see there are multiple posts listed when there really should be only one. This feature would be extremely useful for another blog I’ve set up. I have the same exact setup there, and it also doesn’t work, but I don’t mind experimenting on my personal blog if you need more info.
Thanks!
Administrator
June 3rd, 2008 at 9:28 am
Hi Philip Yurchuk, I’ve just done a small update to the plugin that might solve your problem. Could you try the dev version and tell me if that makes a difference?
Thanks
Guest
June 8th, 2008 at 1:04 am
I really appreciate the effort, but it still isn’t working. Here is an example link:
http://philip.yurchuk.com/category/software/?tdo_tag=rhino
You can see there are a couple posts that don’t have the rhino tag.
Administrator
June 9th, 2008 at 9:45 am
Hi Philip, did you try disabling Simple Tags plugin (just in case their is a conflict)? Are you using any plugins that might be modifying WP_Query (i.e. messing with the order of posts in the template)?
Guest
June 11th, 2008 at 5:46 am
Here are the plugins I have activated (latest versions):
Askimet
Simple Tags
Subscribe to comments
Wordpress Database Backup
WP-Footnotes
I have tried disabling each plugin, but that didn’t fix it. I searched for wp_query in my theme (Tarski), but nothing was found. I’m running PHP 4.4.7 and MySQL 4.1.22. Thanks for your help.
Guest
June 13th, 2008 at 6:38 am
Hi,
You got a really great plugin going here, I was about to code something similar myself when I can across it. I’ve had it working quite nicely and added a few enhancements which can be seen at http://www.easymapinfo.com/wordpress25/category/australia/ (still under dev).
The problem that I was having is when intersecting a category and multiple tags expecting an ‘OR’ join to take place and was getting a ‘AND’ join result. eg …/categoryname/?tdo_tag=tag1,tag2. The plugin correctly modifies the title but the result is definitely a ‘AND’ join.
So I threw a virgin WP install at http://easymapinfo.com/virginwordpress/?cat=3 with only your plugin and it does the same thing.
Thoughts?
Administrator
June 13th, 2008 at 9:16 am
Hi Joel Giddey,
I wonder is it something to do with the version of WordPress. It was working correctly on WP2.3 where I did the initial development. I haven’t properly tested it on WP2.5.1 yet, so maybe somethings been broken. Have you checked the bugs list?
Guest
June 14th, 2008 at 6:30 am
I’ve checked the bug list on trac there is one there that is is slightly relevant but not directly to this issue. So I installed a fresh WP 2.3 with a fresh tdotf on http://easymapinfo.com/wordpress23/category/cat1/ and when is use tdo_tag=tag1,tag2 I’m still getting a ‘AND’ join result.
Was thinking it may be as a result of
$args->set_query_var('tag_slug__and',$tags);on line 149 of tdotf.php but when I try tag_slug__in I get no results. I think this may have something do to with query.php around line 1126 where WP seems to only handle intersects with tag_slug__and and not ‘in’.So until I find a solution I think I’m going to modify my changed tdotf to use radio buttons and not checkboxes and limit users to one cat with one tag intersects.
But I am surprised that you had it working with your 2.3 install, was it dependant on any other plugins?
Thanks!
Administrator
June 16th, 2008 at 10:13 am
Hi Joel,
I’ve done some digging. Your right. Tags with an OR join do not intersect with categories. This seems true for WordPress 2.3 too. I’ve gone through the WordPress code and it’s not supported at all. I think I can make it work though by doing some magic with filters, so I’ll see what I can do.
Administrator
June 16th, 2008 at 10:38 am
I’ve got a filter implemented now that correctly updates the intersection query when you have a set of tags that are ORed instead of ANDed. I’ll add it to the SVN later today, but if your in a here, here is the actual code you can add to the plugin:
function tdotf_query_filter($where) { global $tdotf_tag_get_var,$wpdb; $tag_query = tdotf_get_tdo_tag_query(); if(!empty($tag_query) && $tag_query != false && strpos($tag_query,',')) { $tags = split(",",$tag_query); // Grab all posts with these tags $sql = "SELECT p.ID FROM $wpdb->posts p INNER JOIN $wpdb->term_relationships tr ON (p.ID = tr.object_id) INNER JOIN $wpdb->term_taxonomy tt ON (tr.term_taxonomy_id = tt.term_taxonomy_id) INNER JOIN $wpdb->terms t ON (tt.term_id = t.term_id)"; $sql .= " WHERE tt.taxonomy = 'post_tag' AND t.slug IN ('" . implode("', '", $tags) . "')"; $sql .= " GROUP BY p.ID"; $post_ids = $wpdb->get_col($sql); // Pattern and replacement for query $pattern = "AND.*$wpdb->posts\.ID.*IN.*(.*)"; $replacement = "AND $wpdb->posts.ID IN (" . implode(', ', $post_ids) . ")"; // Update query $where = preg_replace('/'.$pattern.'/', $replacement, $where); } return $where; } add_filter('posts_where_request','tdotf_query_filter');Administrator
June 16th, 2008 at 11:42 am
The code I posted is slightly incorrect. I’ve done the change and its sitting in the SVN repo, so anyone can grab the dev version right now with the fix. I’ll probably release it officially during the week.
Guest
July 2nd, 2008 at 1:07 am
Hi!
I’d love to find out how to emulate the ‘tag surfer’ functionality that wordpress.com users have.
Any ideas? I thought it might be possible to use your plugin and add some php code to change the links associated with the tags that are displayed.
For example, I could change the hyperlink of a tag (e.g. mywebsitestag [+]) so that it will append the tag to the existing url, or I could change the hyperlink (e.g. mywebsitestag [x]) so that on clicking it, it will jump the user to the same url minus the tag selected.
does this make sense?
many thanks
scotjam
Administrator
July 2nd, 2008 at 9:41 am
Hi Scotjam, what is the “tag surfer” functionality? I’m not familiar with it. If I know what it does, I can see if its doable.
Guest
July 14th, 2008 at 8:18 pm
Great work on the fix to the plugin, I was digging through the new code and it really is a clever bit of work with the ‘OR’ joins.
For those interested I’ve finalized my implementation of the plugin over at my site a good url example is http://travel.accommodationsphere.com/earth/south-africa/gauteng-za/ look over at the left for accommodation types which are actually tags using the tdo_tag_fix with a few mods.
Regards
JG
Guest
July 14th, 2008 at 10:02 pm
Hi Joel
Brilliant site. Just one question, how did you get to make sub categories work with tags?
I was under the impression that tdo only works with single category intersections with one or more tags. But you’ve got sub categories working which is brilliant!
Also, I like the way the checkboxes are filtered. A very nice touch indeed.
cheers
July 15th, 2008 at 8:59 pm
TDO tag fixes with a twist…
For those who are not familiar with TDO tag fixes, its a fantastic plugin that makes up for alot of wordpress’s shortfalls in what i like to call ‘filtering’ posts. It basically allows you specify exactly what posts you want shown bas…
Guest
July 27th, 2008 at 1:23 am
the plugin is fantastic, thank you.
i am having 2 issues though that i just can’t sort out.
i have included
but when using on a page like
?cat=6&tdo_tag=tagename
is it possible to have the cloud generate links like
?cat=6&tdo_tag=tagename+anothertag
also, i can’t get the permalinks to work, they always show like
tdo_tag=tagname
any ideas?
Administrator
August 4th, 2008 at 10:48 pm
Joel Giddey: Nothing you can’t do with some regex!
dave: If you want the tag cloud to generate different links, you’ll need to modify the code yourself currently.
Also what do you mean by the permalinks aren’t working?
Guest
August 10th, 2008 at 6:12 pm
I would really like this to work with http://codex.wordpress.org/Template_Tags/query_posts;
I need to use this functionality below.
query_posts($query_string . “&showposts=1″)
Has anyone figured this out.
I need it badly and cant get it.
Guest
August 13th, 2008 at 1:13 pm
Hi !
This plugin is just what I need, but it doesn’t work at all with me.
I have WordPress 2.5.1.
I try to display:
the category: 2008-07-bali
AND
the tag: plongee
with the following url:
http://petitesbullesdailleurs.fr/category/2008-07-bali/?tdo_tag=plongee
but the result is similar to:
http://petitesbullesdailleurs.fr/category/2008-07-bali/
Any idea or suggestion?
Many thanks!!!
Corinne
Guest
August 14th, 2008 at 12:30 am
You must be having the same problem as me.
In your archive.php you must be using a custom query and that is the problem.
Administrator
August 14th, 2008 at 8:50 am
Yes Jackeye your right. If you’re using a plugin or a theme that creates a custom query, it prevents tdo-tag-fixes from actually modifying the query.
I just spent a few days trying to build a custom query in a theme that doesn’t break tdo-tag-fixes so it’s not easy.
Guest
August 16th, 2008 at 6:41 pm
Ya It seems any query I use will break it.
If you use
it breaks the normal wordpress tags so maybe it needs to pass $query_string somewhere in the plugin.
I dont know the first thing about this though.
Guest
August 16th, 2008 at 6:42 pm
Ya It seems any query I use will break it.
query_posts($query_string . “&showposts=5″)
If you use query_posts(“showposts=5″)
it breaks the normal wordpress tags so maybe it needs to pass $query_string somewhere in the plugin.
I dont know the first thing about this though.
Administrator
August 21st, 2008 at 8:58 am
Yes it will. There isn’t an easy solution. What I assume your doing is in your category template in your theme your trying to modify the wp_query object. However, the query has already been executed by then, so setting new parameters will require running the query again, and it’ll forget the tdo-tag stuff!
The only way to do it is basically do it the way tdo-tag-fixes does it by creating a filter that modifies the query before it’s called (i.e. before the actual theme).
If anyone wants to know how to do this, please ask and I’ll write up a short tutorial. I did this on my current theme so that I could do some mods to the query without breaking tdo-tag-fixes.
Guest
August 21st, 2008 at 8:35 pm
Yes please tell us how to do this!
Guest
August 29th, 2008 at 4:10 pm
Are you going to post this. I would really appreciate it.
Thanks.
Administrator
August 31st, 2008 at 12:15 pm
Plan to do it Monday!
Administrator
September 1st, 2008 at 9:27 am
Done. Hope everyone finds it helpful.
Guest
September 3rd, 2008 at 1:18 am
Thank you for posting this, but I found a new way to do it.
http://trac.wordpress.org/ticket/5433
It looks like the tag category intersection will be fixed in wordpress soon and for now I can just use &tag=a+a
Guest
September 3rd, 2008 at 1:55 am
Here is the link related to my last comment
trac.wordpress.org/ticket/5433
Administrator
September 3rd, 2008 at 9:27 am
If you read through the comments, it was meant to be fixed in wp2.3 and they didn’t bother doing it for wp2.6.1. I wouldn’t hold much out for it. Still, if they do, that’d be great and I can retire this plugin (probably).
Guest
November 3rd, 2008 at 6:32 pm
Thanks for this great plugin.
I’ve got
in my sidebar and it works great.
It generates the link:
http://localhost/blog/index.php/category/news/?cattag=sketching
However
is not working in the post metadata.
It generates the link
http://localhost/blog/index.php/category/?cattag=sketching
which returns a 404.
The category name: /news/ seems to be missing in the URL. How can I get the function tdotf_the_tags to also write the category name in the URL?
November 7th, 2008 at 6:54 pm
[...] TDO tag fixes [...]
November 8th, 2008 at 2:06 am
[...] you need to download the TDO Tag Fixes WordPress Plugin which gives you more flexibility in your incorporation of tags. Then you will want to add the [...]
Guest
November 9th, 2008 at 5:24 pm
Thank you – I’ve been brainstorming on this since late, late Friday night – and this seems to do what I needed.
This is how I applied it. At the bottom of single.php, I added this code:
<a href=”http://site/category//?tdo_tag=additional-recommendations”>Additional Recommmendations for
<a href=”http://site/category//?tdo_tag=stories”>Stories for
On my site, each post name has a corresponding, identical category name (that is the only way this would work from what I see). Each category/post name has additional categories that need to be part of each main post/category: additional recommendations, stories…but since intersecting categories doesn’t work in WordPress, changing those “subcategories” to tags and using your plugin made this work. Now, for the 300 post/category combinations, I only needed one piece of code to support the automation of this part. Thanks!
Guest
November 10th, 2008 at 4:55 am
Hey there! Great plug-in. This solved my problem for a website that lists industries (tags) in cities (categories). I’m now able to go into a city and list a tag cloud of all the industries in that city. You can see yourself at Studentrabatt.no (a Norwegian website that lists all the student discounts in Norway).
I have a question. On the city (category page), I have some banners in the right margin. I’d like to offer different banners for different cities, which is solved by the following code:
However, when I drill into an industry from there (tag), I’d like to show a different banner ad. I’m looking for some code that does something like “if this category AND this tag then echo Banner ad 2″.
The goal is to offer very specific ads to companies in certain industries for certain cities.
Is this possible currently? If not, would it be a lot of development, and do you know of anybody who’d be interested in helping out? (hint hint
…
Administrator
November 10th, 2008 at 10:56 am
I’ll have to have a look at it, when I get the chance. I haven’t extensivily tested that part yet.
Administrator
November 10th, 2008 at 10:59 am
Bjorn, your code seems to have been stripped out of your comment. Any chance you could try posting it again, but with the < and > replaced with < and >? (it’s the angle brackets and “php” references that get the code stripped out)
Guest
November 10th, 2008 at 4:38 pm
Is there a way to create a custom template page for when people are on an intersect page for a category+tag, i.e
category+tagname.php?
Guest
November 10th, 2008 at 4:51 pm
Sorry, it was basically an IF statement using is_category. If it is_category, then show the banner. That works for me – if it is a certain city, then show a certain banner. However, I’m trying to make an IF statement for a certain city and industry (intersection of a category and tag) and only show the content then. Does that make sense?
Guest
November 11th, 2008 at 7:58 am
Hi Mark
Problem solved. There was a problem with the tdotf_the_tags when used on category pages. Thanks to the comment by QueenVictoria (#comment-103241) I was able to solve the problem.
In the tdotf.php file, I replaced the code beginning on line 399:
function tdotf_the_tags( $before = ”, $sep = ”, $after = ” ) {
global $tdotf_tag_get_var,$cat;
if(is_category() && isset($tdotf_tag_get_var)) {
$tags = get_the_tags();
with the following:
function tdotf_the_tags( $before = ”, $sep = ”, $after = ” ) {
global $tdotf_tag_get_var,$cat;
if ( ! $cat ) {
$category = get_the_category();
$cat = $category[0]->cat_ID;
}
if(isset($cat) && isset($tdotf_tag_get_var)) {
$tags = get_the_tags();
and this did the trick.
One thing to note is that tdotf_the_tags was misspelled in the original file (as tdof_the_tags). I suppose either spelling would work, but I changed it to tdotf_the_tags for consistency.
-Mark
Guest
December 3rd, 2008 at 3:29 pm
Hi Just letting you know that this plugin is breaking my site when using WordPress 2.6.2. It crashes any page where the Tag Cloud is featured.
Thanks anyway, it sounds like a good plugin!
Administrator
December 3rd, 2008 at 4:03 pm
Could you give me more information please? I’m using the plugin on this website which is WordPress 2.6.3 with no crashes (as you can see). Have you tried disabling all your other plugins to see if there is a clash? It might also be an issue with your theme.
Guest
January 15th, 2009 at 4:23 pm
@Tommy, I am using it on 2.6.2 without any crashes. looks like you have any modification installed which is causing the problem.
Guest
February 4th, 2009 at 4:13 pm
hello
Bjorn, your code seems to have been stripped out of your comment. Any chance you could try posting it again, but with the replaced with < and >? (it’s the angle brackets and “php” references that get the code stripped out)