This answer provides the code for a query that returns an OR match on a taxonomy term:
global $query_string; $args['tax_query'] = array( array( 'taxonomy' => 'status' ,'terms' => array( 'available', 'pending' ) // change to "sold" for 2nd query ,'field' => 'slug' ), );
I'd like to have my taxonomy template retrieve the term values for the array ( ,'terms' => array( 'available', 'pending' ) ) from the URL, the same as for the single term.
The point is to allow taxonomy terms to change over time, without having to hard-code page templates for particular combinations of interest, so that, if there's a better way, please suggest it.
Thanks to this post I have permalinks mapping to template files as follows:
example.com/cptslugs maps to my archive-cptname.php template. example.com/cptslug/cpt-post maps to my single-cptname.php template. example.com/cptslugs/ctxslug/term maps to my taxonomy-ctxname.php template.
I'd like to have something like:
map to my taxonomy-ctxname.php template such that get_query_var( 'term' ) returns an array of terms (term1,term2) from the url.
but if I could get
to map to my taxonomy-ctxname.php template such that get_query_var( 'term' ) returns an array of terms (term1,term2) from the url, perhaps via a rewrite rule and a filter, that would be ok, too.
But either way, the idea is that the template file should work, whether it's passed one term or an array of terms.
Ok - @scribu to the rescue! -- maybe. Kept searching, and this is what I found. Thought I had it all figured, but I can't get it to work.
query_posts( array( 'tax1' => 'term1,term2', 'tax2' => 'term3+term4' ) );
which further maps to:
query_posts( array( 'tax_query' => array( array( 'taxonomy' => 'tax1', 'field' => 'slug', 'terms' => array('term1', 'term2'), 'operator' => 'OR' ), array( 'taxonomy' => 'tax2', 'field' => 'slug', 'terms' => array('term3', 'term4'), 'operator' => 'AND' ), ) );
renders the front page template. Revision: it renders taxonomy-ctxname.php when you spell ctxname correctly. Imaging that!
(taxonomy is registered with a slug of cptslug/ctxslug) also renders the front page template.
renders the archive-ctpname.php template.
How do I get a URL that renders the taxonomy-ctxname.php or the taxonomy.php template?
Then, once I get that down - suggestions for pretty urls are welcome but not absolutely necessary.
Both render taxonomy-ctxname.php as desired. See details in my answer, posted below.