Relative post count in filter terms
-
Great Plugin! Especially the new Ajax feature to exclude empty-results filter combinations is very promising.
However I do have some issues with it:
If I select “show post count of terms” in the advanced options, the displayed numbers at the front-end are absolute and don’t take the other filter’s setting in account. (Ajax on or not).
Is it possible to automatically update the post-count for the terms, so that the number represents the amount of posts that the user can actually expect in the query? (Considering the other filters that are set)On my website I want users to select a term from my main taxonomy “angebotscat = arbeit” by clicking on the navigation and then be able to filter down through secondary taxonomies (stadteil = arsten). So the user is always guided into a post-type-archive with the main taxonomy term preselected.
Let me show you an example from my archive-main_taxonomy.php post type archive template:
This is the url you’re looking at: (sorry for the use of non-english terms)
wtb = local directory of this wordpress instance
angebotscat/arbeit = my main taxonomy / term
stadteil/arsten = one of 3 secondary taxonomies / termNormally I’ve hidden (in CSS) the first filter field with the main taxonomy, to keep the user in the same main taxonomy term, but this brings up an issue: As you can see, the secondary taxonomy term “Arsten” has a higher post count (61) than the main taxonomy term “Arbeit” (33). If the user can’t see the filter dropdown, they will very likely be confused when the numbers don’t correspond to the post-query output.
So I thought what if I can at least count only posts that are both in my main taxonomy “angebotscat” + “current term” as well as in each secondary taxonomy term.
Looking at your code I tried a dirty little hack at public/class-beautiful-taxonomy-filters-public.php, but that returned 0 for all other taxonomies in the filters.
See my faulty hack in the tax_query here:
/** * Fetch post count for terms based on a single post type * * @since 1.2.8 */ public static function get_term_post_count_by_type($term, $taxonomy, $post_type){ $args = array( 'fields' =>'ids', 'update_post_meta_cache' => false, 'no_found_rows' => true, 'posts_per_page' => 10000, // We don't set this to -1 because we don't want to crash ppls sites which have A LOT of posts 'post_type' => $post_type, 'tax_query' => array( 'relation' => 'AND', array( 'taxonomy' => $taxonomy, 'field' => 'slug', 'terms' => $term ), array( 'taxonomy' => 'angebotscat', //my pre-selected main taxonomy 'field' => 'slug', 'terms' => $term ), ), ); $postcount_query = new WP_Query( $args ); return ( count($postcount_query->posts > 0) ? count($postcount_query->posts) : 0 ); }
What am I doing wrong here?
Also will there possibly be a future admin option to properly include taxonomies in the rewrite but exclude from filter dropdown display?
- The topic ‘Relative post count in filter terms’ is closed to new replies.