Query two taxonomies via URL or link?

I’ve been banging my head about this, and have created a work-around, but it would be much nicer for my site’s organisation if I could figure this out.

I want to be able to query posts across two taxonomies (one of which is custom), I’d like to be able to do this automagically, without needing to create custom templates with custom DB queries.

Read More

I want to have a platform custom taxonomy, and in the same time to be able to label articles as category (such as review or preview terms).

At the moment I use a customised Walker to allow me to use the built-in Menu system to generate menus that point to specific archive pages.

My URL looks like:

example.com/category/platforms/consoles-platforms/ps3+review/

This finds articles that are in the PS3 portion of platforms AND in the Review category. Currently this is all done under the normal wordpress category taxonomy.

Ideally I’d want them to be separate taxonomies, (Reviews being part of normal Category tax and then a Platform tax for console organisation) so that the URL could look like:

example.com/platforms/consoles/ps3/review

It looks nicer and would let me keep my categories more tightly organised. BUT I can’t for the life of me see how you set up WordPress to query across two taxonomies automatically.

Has anyone else come up against this?

Edit: Following Rarst’s comment, I have to wonder, am I being too ambitious with my URL requirement? I could feasibly set this up using GET parameters and just one template (i.e., example.com?platform=ps3&type=review); is that the simplest/most robust way? Any other ideas on how to solve this?

Related posts

Leave a Reply

1 comment

  1. I think you could get it working with category__and

    I remember trying a similar approach to yours and found out that I would get content that was either in platform and/or in review. But to get actually posts that where only on both, excluding posts that were just in one of them, this was my approach. Maybe the way you have your posts works with that approach, but it didn’t with mine (which was more like city / type of event / cost of the event).

    Anyway, you could pass your combination of elements through POST, and then on the receiving page get those elements into the array:

    $myFilteredArray = array();
    if (isset($_POST['.... 
    // Do what you need to get the POST variable elements
    into the array
    
    // and then, use this query format
    query_posts( array(
                'category__and' => $myFilteredArray, 
                'orderby' => 'title',
                'posts_per_page'=>-1, 
                'order' => 'ASC')
                );