wordpressfeedrss2

Wordpress feed of posts in multiple categories


I'm trying to figure out the proper URL for a Wordpress category feed that contains posts that are in multiple categories. By that I mean I've got categories 28 & 31. I want a feed of posts that are in 28 AND 31, not 28 OR 31.

What I've been able to find is this format: http://mydomain.ca/?cat=28+31&feed=rss2 . The + is supposed to be an AND operator. I could use a comma instead, but that's an OR operator.

When I use the comma, the feed loads fine. When I use the +, I get nothing. Not even a blank page - the browser just refuses to go anywhere and the URL bar gets reset to whatever URL I had in there previously.

I'm using the latest Wordpress 3.4.2 version.

Also FYI - I'm not using pretty permalinks because Wordpress decided to not function properly at about 2:00 yesterday - so I'm trying to recover from that.


Solution

  • As far as I can see, this is kind of a bug for the standard category taxonomy. In fact, if you try that syntax with any other taxonomy, it works. So, a workaround could be to convert the standard category taxonomy into a custom taxonomy and make it behalf as a category with 'hierarchical' => true. Then you will be able to use something like:

    ?custom-taxonomy=slug1+slug2.

    Not very elegant, but it could be a solution for you.

    EDIT: As WordPress evolved, we can say that the standard Category and Tags became special cases of the Taxonomy concept. Each of them is a default Taxonomy for posts. Since version 2.3 WordPress introduced custom taxonomies. With custom taxonomies, you can create any kind of special taxonomy, with some possible customization, that make them behalf more like a tag or more like a category. That said, they all work with the same syntax, let's say:

    yoursite.com/?taxonomy-name=taxonomy-item

    That url will list all the posts categorized as taxonomy-item. For some reason (a bug, I guess), the standard ?cat=1+2 does not work as it should, but every other taxonomy does, indeed. To be clear, you could replace

    yoursite.com/?cat=dogs+cats

    with

    yoursite.com/?pets=dogs+cats

    by creating a custom taxonomy named 'pets'. And that will do the job.

    If you create a custom taxonomy, and use it as a replacement to you standard category, you would be able to make this work with no further development. If you are unfamiliar with custom taxonomies, try the Custom Post Type UI plugin, that will do the dirty work for you. The most important setting in order to have a custom taxonomy that behaves as the default categories is to set it as hierarchical.

    Let's say you create a custom taxonomy called "new-cats". After that, you will be able to use yoursite.com/?my-cats=cat1+cat2 and that will list post categorized with cat1 AND cat2. By the way, this could give some SEO benefits out of the box. Of course, you will need to categorize all of your posts with the new taxonomy. Something like this could help http://themespotter.com/how-to-convert-post-tags-to-custom-taxonomies-in-wordpress/