Available since: 2.8.7
searchwp_indexer_taxonomy_term
View Parameters »Note: Use of this hook will require a manual reindex
By default SearchWP will index the taxonomy terms associated with posts as they’re indexed if the taxonomy has been added to an engine configuration.
If you would like to index additional taxonomy term data alongside the term itself, you can use this hook:
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
<?php | |
// Index taxonomy term metadata alongside taxonomy term in SearchWP. | |
add_filter( 'searchwp_indexer_taxonomy_term', function( $to_index, $context ) { | |
$term_meta = get_term_meta( $context['term']->term_id, 'my_term_meta_key', true ); | |
// If the metadata exists, append it to the string to be indexed by SearchWP. | |
return ! empty( $term_meta ) ? $to_index . ' ' . $term_meta : $to_index; | |
}, 10, 2 ); |
Parameters
Parameter | Type | Description |
---|---|---|
$term |
String |
The taxonomy term |
$context |
Array |
|