WordPress: Can’t query blog items that are in both category A and category B?

Posted by Pierre Igot in: Blogging
January 19th, 2005 • 12:27 am

I have been working hard on finalizing the new web site that I am designing for my employer. It’s not a blog, but I am using blogging software — the open source WordPress — behind the scenes to handle the dynamic part of the site and enable other contributors to easily post new items on the web site.

Unfortunately, I am encountering a few issues rather late in the game. One of them has to do with some basic aspect of the WordPress architecture. WordPress supports multiple categories and subcategories for blog posts. When posting a new blog item, you can file it under a single category or under several different categories. It’s just a matter of checking one or several checkboxes.

For example, you can have a blog item about iTunes that you can file under both the “Music” and “Macintosh” categories.

My problem is with reading posts and searching for specific posts. Given the fact that you can do the above, i.e. file a single blog item under several different categories, you would think that there would be an easy way to search for posts that appear under both category A and category B.

Unfortunately, it doesn’t appear to be the case. In order to access posts in the “Music” category, the standard query string in the URI is the following:


This is straightforward enough. But then what is the query string to request blog items that appear in both the “Music” category and the “Macintosh” category?

I tried


but it doesn’t work. It returns blog items that appear either in the “Music” category or in the “Macintosh” category.

In other words, the default underlying logical operator here appears to be OR and not AND.

Is there a way to change the logical operator to AND? Not as far as I can tell. I’ve been through pages and pages of documentation about both WordPress and PHP, and couldn’t find anything.

I posted a request for help on the WordPress forum and the response I got seems to indicate that this cannot be done easily, that it requires advanced PHP scripting — which unfortunately is beyond my skill level at this point.

My hope was that I would be able to use a simple query string as part of a URI in order to request this particular selection of posts, so that I could use a simple link on the web page for people who want to see posts that belong to both categories. At this point, it doesn’t look like I will be able to do this. I might have to learn more about PHP scripting first. And since I want to be able to do this for a whole range of category combinations, it’ll require a certain level of abstraction, which will make things even more complicated.

This is disappointing, as I would expect this kind of functionality to be built into a blog engine that actually supports a fairly sophisticated category structure.

Comments are closed.

Leave a Reply

Comments are closed.