Created
November 7, 2023 13:36
-
-
Save LaxusCroco/38e642ec8ae2e2fcbfc3467998566eba to your computer and use it in GitHub Desktop.
Adds the ability to display the name of the related term in the Custom Field area of Ajax Search. In the Key field, enter post_terms__category where the 'category' part should be replaced with the taxonomy slug.
This file contains hidden or 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 | |
add_filter( 'jet-search/template/pre-get-meta-field', function($value, $meta, $post){ | |
$meta_key = $meta['meta_key'] ?? ''; | |
if( false === strpos( $meta_key, 'post_terms__' ) ){ | |
return $value; | |
} | |
$tax_slug = ( explode('post_terms__', $meta_key) )[1]; | |
if( ! taxonomy_exists( $tax_slug ) ){ | |
return $value; | |
} | |
$terms = wp_get_post_terms( $post->ID, $tax_slug, array('fields' => 'names') ); | |
return array( implode(', ', $terms) ); | |
}, 10, 3); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment