Added support for filter on taxonomy archive
-
I wanted different sidebars based on term-filtered list – rather than just on the taxonomy itself. So I added the following code:
public function get_sidebars($handle = "!= '2'") { global $wpdb, $post_type, $wp_query; [ ... ] if(is_singular()) { [ ... ] // Taxonomy archives } elseif(is_tax() || is_category() || is_tag()) { $term = get_queried_object(); $terms = array(); foreach ($wp_query->tax_query->queries as $taxterm) { foreach ($taxterm['terms'] as $k => $termid) { $termobj = get_term_by( $taxterm['field'], $termid, $taxterm['taxonomy'] ); $terms[] = $termobj->slug; } } $joins .= "LEFT JOIN $wpdb->term_relationships term ON term.object_id = posts.ID "; $joins .= "LEFT JOIN $wpdb->term_taxonomy taxonomy ON taxonomy.term_taxonomy_id = term.term_taxonomy_id "; $joins .= "LEFT JOIN $wpdb->terms terms ON terms.term_id = taxonomy.term_id "; $joins .= "LEFT JOIN $wpdb->postmeta post_tax ON post_tax.post_id = posts.ID AND post_tax.meta_key = 'taxonomies'"; $where .= "(terms.slug IN('".implode("','",$terms)."')";
It might not work 100% for post tag archives – but it’s running on a site that doesn’t use posts, so that’s not a problem for me.
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘Added support for filter on taxonomy archive’ is closed to new replies.