Please note!

This is an archived, inactive copy of
"WordPress Loop hack/replacement with logical operands for multicategory listings"

Please do not link to this page.


February 17, 2006

WordPress Loop hack/replacement with logical operands for multicategory listings

Posted by bopuc at February 17, 2006 06:58 PM

I just posted this on the WordPress support forums, see if it gets me anything. If you here have any thoughts please please please get in touch. :)

Hi gang,
While poking around for this post, I discovered that WP does handle multi-category listings when you feed it ?cat=23,54,76 but does so with (I think) an OR logical operand.
In other words, it returns posts categorized as any one of the requested categories.

My needs are bit more elaborate... First of all, I'd like the above example to return *only* posts categorized as *all* the requested categories (post is categorized as 23, 54 and 76. If not, I don't want it.)

Further, and this is where it gets really tricky, at least too tricky for me right now, I'd like to mix and match both logical operands.

for example I'd liek all posts that are categorized as 23, and either 54 or 76 (23 and 54, 23 and 76, and --if existent-- 23, 54 and 76)

This means introducing logical operators in the query string and parsing them out right?

?cat=23-AND-(54-OR-76) or some such.

For now I'd settle for the first one though... any ideas? Any existing plugins? I'm willing also to forgo pretty URLs for this feature (i.e. no .htaccess rules required.. dealing with /categories/china-OR-india-AND-free_speech could get nasty.)

Comments

should i even bother saying "drupal does that"? ;)

Posted by: James Walker at February 17, 2006 08:13 PM

Hah! :)
Maybe I'll go dig out that code and port it...

Posted by: Boris at February 17, 2006 08:53 PM