Skip to content

Instantly share code, notes, and snippets.

@jchristopher
Last active April 19, 2019 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jchristopher/652bdc438d919d4846b63daf8ed9bf0f to your computer and use it in GitHub Desktop.
Save jchristopher/652bdc438d919d4846b63daf8ed9bf0f to your computer and use it in GitHub Desktop.
Index taxonomy term metadata alongside taxonomy term in SearchWP
<?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 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment