0

I have a custom post type Book which has three custom taxonomies:

  • Genre
    • Fiction
    • Non-fiction
  • Media Type
    • Book
    • eBook
    • Audiobook
  • Audience
    • Kid
    • Teen
    • Adult

My goal is to create index (aka archive) pages of many of the different combinations of two or all three taxonomies. For example, I want a "Kids Fiction" page and an "Adult eBook" page. If at all possible, I want to do this without any PHP because custom PHP tends to have lots of hardcoded properties that make the template hard to maintain.

How do I create index pages with different combinations of multiple taxonomies?

0

This is very similar to this question.

Try something like this in your template and change the AND condition to AND/OR as appropriate depending on what combination you want.

$args = array(
'post_type' => 'Book',
'tax_query' => array(
    'relation' => 'AND',
    array(
        'taxonomy' => 'Genre',
        'field' => 'slug',
        'terms' => array( 'Fiction' )
    ),
    array(
        'taxonomy' => 'Media Type',
        'field' => 'slug',
        'terms' => array( 'eBook' )
    )
)
);
$query = new WP_Query( $args );
|improve this answer|||||
  • Yes. It is similar. However, it is different in that I am asking for a non-PHP solution. Are you suggesting that there is no solution for this problem that doesn't involve writing PHP? – Jeff Jun 13 '14 at 16:43
  • The only other option that I can think of is to use jQuery to filter out the items you want/don't want on the page. I'm not sure I understand your statement "...because custom PHP tends to have lots of hardcoded properties that make the template hard to maintain..." Even with jQuery you're going to have to identify (via a css class) which elements you don't want to show and that class name will have to be hard-coded anyway. – leromt Jun 13 '14 at 16:50
  • I mean that if I hard code the taxonomy terms or the pages that need to use the taxonomy terms, content authors will need to come to me in the future to make adjustments. Maybe they want to add Romance as a genre next month but they would need development support to get a "Kids Romance" page. (Sorry... I couldnt resist that weird juxtaposition) – Jeff Jun 13 '14 at 17:06
  • Okay, so in that case, perhaps you just need to create a custom category archive template and name it accordingly for each of the parent categories. See the diagram on this page and use it as a guide as to how the template hierarchy works. – leromt Jun 13 '14 at 17:13
  • That isn't directly applicable is it? I'm talking about taxonomies and you mentioned categories. My taxonomies are not hierarchical. – Jeff Jun 13 '14 at 19:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.