1

I know there have been similar answers but I'm not having any luck.

I have a custom taxonomy called events. I would like to see all the post from all terms here: domain.com/events/

That doesn't work though it gets a 404. This works though domain.com/events/term

How do I get it to work with the other way also?

1

Redid this. It should now work for any and all post_types:

<?php
add_action('init', 'setup_events_rewrite');
//Gives you a new query var and sets up a rewrite rule that makes events/ work
function setup_events_rewrite() {
    //create a query var
    add_rewrite_tag('%tax_archive%','([^/]+)');
    //set new query vart with tax of choiice
    add_rewrite_rule( 'events/?$', 'index.php?tax_archive=events', 'top' );  
}

add_filter('request', 'setup_events_request');
//sets the post_type is tax_archive is set to events
function setup_events_request($qv) {
    if(isset($qv['tax_archive']) && $qv['tax_archive'] == 'events') {
        $qv['post_type'] = 'any';   //set post type to whatever you like here
    }

    return $qv;
}

add_filter( 'posts_clauses', 'setup_events_post_clause', 10, 2 );
//If the query var tax_archive is set and is equal to events, it'll change the query to pull only posts that have a term from the events taxonomy
function setup_events_post_clause($clauses, $wp_query) {
    global $wpdb;
    if(isset($wp_query->query['tax_archive']) && 'events' == $wp_query->query['tax_archive']) {
        $clauses['join'].= <<<SQL
LEFT OUTER JOIN {$wpdb->term_relationships} ON {$wpdb->posts}.ID={$wpdb->term_relationships}.object_id
LEFT OUTER JOIN {$wpdb->term_taxonomy} USING (term_taxonomy_id)
LEFT OUTER JOIN {$wpdb->terms} USING (term_id)
SQL;

        $clauses['where'] .= $wpdb->prepare(" AND taxonomy = %s", $wp_query->query['tax_archive']);
        $clauses['groupby'] = "object_id";      
    }

    return $clauses;
}
?>
  • I was hoping that it would work but it's just showing everything I have for index. If I do &events=term+term that works. Is there a way to output all the terms of a taxonomy with the divider being a "+"? Thanks for your help! – kel Sep 5 '11 at 6:01
  • @kel: new solution added. This one should work. – Manny Fleurmond Sep 5 '11 at 12:42
  • that works if I change the post_type=post to the post type I'm using. The issue I will run into is that taxonomy can be used on different post types. Is there a way to include all post types or to specify the post types I want to use? Thanks again. – kel Sep 7 '11 at 22:56
  • @kel: Got it working for any post type. Change the post type in the setup_events_request function either by changing it to one or creating an array (array('post', 'page', 'whatever')) – Manny Fleurmond Sep 8 '11 at 12:26
  • I don't know why I'm not getting this I change $qv['post_type'] = 'any'; to entertainment it's not working. Bu in the URL if I go to ?tax_archive=events&post_type=entertainment it works just fine. – kel Oct 22 '11 at 1:09

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.