• Resolved vkranendonk

    (@vkranendonk)


    I have taxonomies connected to multiple post types. This makes the ‘hide_empty’ on ‘wp_dropdown_categories’ not work, because this does not check on post type AND term.

    As an example:
    – Post in post type ‘Book’ -> Tax ‘Vintage’ (contains post ‘Dante’)
    – Post type ‘DVDs’ -> Tax ‘Vintage’ (contains no posts)

    Then on the DVD archive page it will still show the Tax ‘Vintage’. Any ideas on how to solve this with a filter? Or perhaps something which can be implemented in the plugin.

    https://www.ads-software.com/plugins/beautiful-taxonomy-filters/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter vkranendonk

    (@vkranendonk)

    I got the solution by applying this https://www.dfactory.eu/get_terms-post-type/ with some modifications.

    Would still be nice if hide empty checks on current post type and on filters already active (but understand this no small fix).

    if ( ! is_admin() ) {
    
      function df_terms_clauses($clauses, $taxonomy, $args) {
    
          if(!($args['hide_empty'] && (empty($args['class']) || $args['class'] == "beautiful-taxonomy-filters-select"))) return $clauses;
    
          $query_post_type = get_query_var('post_type');
          $args['post_type'] = is_array($query_post_type) ? $query_post_type : array($query_post_type);
    
          if (!empty($args['post_type'])) {
            global $wpdb;
    
            $post_types = array();
    
            foreach ($args['post_type'] as $cpt) {
              $post_types[] = "'" . $cpt . "'";
            }
    
            if (!empty($post_types)) {
              $clauses['fields'] = 'DISTINCT ' . str_replace('tt.*', 'tt.term_taxonomy_id, tt.term_id, tt.taxonomy, tt.description, tt.parent', $clauses['fields']) . ', COUNT(t.term_id) AS count';
              $clauses['join'] .= ' INNER JOIN ' . $wpdb->term_relationships . ' AS r ON r.term_taxonomy_id = tt.term_taxonomy_id INNER JOIN ' . $wpdb->posts . ' AS p ON p.ID = r.object_id';
              $clauses['where'] .= ' AND p.post_type IN (' . implode(',', $post_types) . ')';
              $clauses['orderby'] = 'GROUP BY t.term_id ' . $clauses['orderby'];
            }
          }
          return $clauses;
    
      }
      add_filter('terms_clauses', 'df_terms_clauses', 10, 3);
    
    }
    Plugin Author Jonathandejong

    (@jonathandejong)

    Hi,

    Ah I see.. yeah as you figured out the hide_empty parameter is part of wp_dropdown_categories and not something I have complete control over at this stage.

    I am thinking I might have to move away from the function eventually to support future features but it’s not something I plan to do shortly.

    Glad you found a workaround!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Hide empty does not work per post type’ is closed to new replies.