Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add filter to remove unavailable terms from facet #2989

Merged
merged 4 commits into from
Sep 16, 2022
Merged

Conversation

burhandodhy
Copy link
Contributor

@burhandodhy burhandodhy commented Sep 6, 2022

Description of the Change

This PR introduces the new filter ep_facet_taxonomy_terms that allows filtering the list of terms in Fact. By using this filter, the user can remove the unavailable terms from the facet. Previously suggested solution has an issue that shows the search box even the available terms are lower than the threshold.

Example: The below code will remove the unavailable terms from facet

add_filter( 'ep_facet_taxonomy_terms', function ( $terms, $taxonomy ) {

	$filtered_terms = array_filter( $terms, function( $term ) {
		return $term->count > 0 ;
	} );

	return $filtered_terms;
}, 10, 2 );

Closes #2760

How to test the Change

  • Add the above code in theme functions.php
  • Add the Facet block in widgets
  • Search for any term and it will only show those terms which are available.

Changelog Entry

Added - ep_facet_taxonomy_terms filter to filter the Facet terms

Credits

Props @burhandodhy

Checklist:

  • I agree to follow this project's Code of Conduct.
  • I have updated the documentation accordingly.
  • I have added tests to cover my change.
  • All new and existing tests pass.

@burhandodhy burhandodhy added this to the 4.4.0 milestone Sep 6, 2022
@burhandodhy burhandodhy assigned burhandodhy and unassigned felipeelia Sep 7, 2022
@felipeelia felipeelia modified the milestones: 4.4.0, 4.3.1 Sep 15, 2022
@felipeelia felipeelia self-requested a review September 15, 2022 18:48
@felipeelia felipeelia merged commit 0f3e197 into develop Sep 16, 2022
@felipeelia felipeelia deleted the burhan/fix-2760 branch September 16, 2022 12:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Exclude facet options if there they are unavailable
3 participants