-
Notifications
You must be signed in to change notification settings - Fork 315
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4067 from 10up/feature-3813/add-new-filter
Add filter to filter Instant Results taxonomy facet terms
- Loading branch information
Showing
4 changed files
with
94 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
tests/cypress/wordpress-files/test-plugins/filter-instant-results-category-terms.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
/** | ||
* Plugin Name: Filter Instant Results Taxonomy Terms | ||
* Description: Filters the Instant Results taxonomy terms for test purposes. | ||
* Version: 1.0.0 | ||
* Author: 10up Inc. | ||
* License: GPLv2 or later | ||
* | ||
* @package ElasticPress_Tests_E2e | ||
*/ | ||
|
||
/** | ||
* Limit the Instant Results terms to only the "Classic" term. | ||
*/ | ||
add_action( | ||
'wp_footer', | ||
function (): void { | ||
?> | ||
<script> | ||
document.addEventListener('DOMContentLoaded', function() { | ||
const filterCategoryTerms = (terms, taxonomyName) => { | ||
|
||
if (taxonomyName !== 'tax-category') { | ||
return terms; | ||
} | ||
|
||
// keep only Term Classic | ||
const filteredTerms = terms.filter(term => term.label === 'Classic'); | ||
return filteredTerms; | ||
} | ||
|
||
wp.hooks.addFilter('ep.InstantResults.filter.taxonomy.terms', 'ep-test', filterCategoryTerms); | ||
}); | ||
</script> | ||
<?php | ||
} | ||
); |