Elementor product loop grid issue
-
Hello,
I recently found this plugin and it seems to be pretty perfect, except I run into an issue that I couldn’t yet get sorted. I want to filter by brands on a elementor pro product loop grid, but I cannot get the brands that has zero product in the category to be hidden. So like on the example page, there is ursuit brand product available, but no bigblue products. Would you have any proposals how to sort out this one?
Thank you in advance
Ville
The page I need help with: [log in to see the link]
-
Hi Ville (@villee),
At the moment, the filter terms themselves aren’t loaded selectively based on the archive, but you can achieve this by using the same filter I have implemented on the plugin’s website. To make it work, give a Query ID to your filter under Filter > Filter Query ID (in this example, archive_filter) and drop the following function into your functions.php file:
add_filter( 'bpfwe/get_terms_args/archive_filter', function( $args, $widget ) { global $wp_query; $post_type = null; $post_ids = []; if ( is_singular() ) { $post_type = get_post_type(); $post_ids = [ get_the_ID() ]; } elseif ( is_post_type_archive() ) { $post_type = $wp_query->get( 'post_type' ); if ( isset( $wp_query->posts ) && ! empty( $wp_query->posts ) ) { $post_ids = wp_list_pluck( $wp_query->posts, 'ID' ); } } elseif ( is_tax() || is_category() || is_tag() ) { if ( is_category() ) { $taxonomy_name = 'category'; } elseif ( is_tag() ) { $taxonomy_name = 'post_tag'; } else { $taxonomy_name = $wp_query->get( 'taxonomy' ); } $taxonomy_obj = get_taxonomy( $taxonomy_name ); if ( $taxonomy_obj && ! empty( $taxonomy_obj->object_type ) ) { $post_type = $taxonomy_obj->object_type[0]; // Use the first associated post type if multiple. } else { $post_type = 'post'; // Fallback to 'post' if undetermined. } if ( isset( $wp_query->posts ) && ! empty( $wp_query->posts ) ) { $post_ids = wp_list_pluck( $wp_query->posts, 'ID' ); } } else { return $args; } if ( empty( $post_ids ) || empty( $post_type ) ) { return $args; } $taxonomies = get_object_taxonomies( $post_type ); if ( empty( $taxonomies ) ) { return $args; } $related_term_ids = []; foreach ( $taxonomies as $tax ) { $terms = wp_get_object_terms( $post_ids, $tax, [ 'fields' => 'ids' ] ); if ( ! is_wp_error( $terms ) && ! empty( $terms ) ) { $related_term_ids = array_merge( $related_term_ids, $terms ); // Add ancestors for hierarchical taxonomies. if ( is_taxonomy_hierarchical( $tax ) ) { foreach ( $terms as $term_id ) { $ancestors = get_ancestors( $term_id, $tax, 'taxonomy' ); if ( ! empty( $ancestors ) ) { $related_term_ids = array_merge( $related_term_ids, $ancestors ); } } } } } if ( ! empty( $related_term_ids ) ) { $args['include'] = array_unique( $related_term_ids ); } return $args; }, 10, 2 );The result should be similar to what you see on this page: https://wpsmartwidgets.com/color/red/, where unrelated terms are pre-filtered automatically.
Please let me know if this solution works for you.
Regards,
DaraHello Dara
This seem not to work on my site, I tried on staging side and I can still see the empty brands.
The example page https://wpsmartwidgets.com/color/red/ looks to be replicating the exact issue I have. The filter by category is showing also empty categories, which I would like to get rid of. I want to use this to brands though, but the issue is the same. So I would like the empty brands on the current query to be hidden. So in your example I would like the Decor and Music be hidden since there is no products.
Would this be possible to sort out somehow?
Thank you
Ville
Hi Ville (@villee),
Thanks for testing the filter. To make things more user-friendly, I’ll be adding a new toggle to the plugin, alongside Dynamic Archive Filtering option, that will also filter the taxonomy term lists.
When enabled, this will automatically exclude terms that aren’t relevant to the current archive query, so the Query ID won’t be necessary for cases like those. This way, empty brands won’t appear if you want them hidden, but you can keep all terms visible if preferred.
This feature will be included in the upcoming version, along with some other improvements. In the meantime, let me know if there’s anything else I can help with.
Regards,
DaraHi Ville (@villee),
Just a quick update to let you know this has now been implemented in version 1.8.4.
You can now enable the new “Filter Terms by Current Archive” toggle in the filter settings. When activated, the term list will automatically reflect the current archive query and will automatically exclude brands that have no products in the current context.
Please update to 1.8.4 and give it a try. If anything is unclear or does not behave as expected, feel free to open a new thread and I will be happy to help.
Regards,
Dara
You must be logged in to reply to this topic.