Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Force Uppercase Search › Reply To: Force Uppercase Search
May 13, 2020 at 3:22 pm
#27298
Participant
Ernest you continue to provide amazing customer support for this product. Worked like a charm just had to
update the Custom Post Type name ‘product_cpt’ and add the return for the results. behold ….
p.s. Good to mark resolved on all fronts! Thank you again.
add_filter('asp_results', 'asp_search_result_interchange', 10, 1);
function asp_search_result_interchange($results) {
// Loop through results
foreach ( $results as $k => &$r ) {
// Check if this is a product
if ( isset($r->post_type) && $r->post_type == 'product_cpt' ) {
// Get Taxonomy Term IDs based on Post ID of Search Result
$term_ids = wp_get_post_terms( $r->id, 'interchange_ct', array(
'fields' => 'ids'
));
// Get Taxonomy Term objects based on applicable Term IDs
$terms = get_terms( 'interchange_ct', array(
'include' => $term_ids,
'orderby' => 'term_order',
'order' => 'ASC',
'hide_empty' => true
) );
// Create array to store unique Term Names
$list = array();
// Add Term Name to list if unique
foreach ( $terms as $term ) {
if ($term->parent > 0 && $term->name !==$product_name && !in_array($term->name, $list) ) {
$list[] = esc_html( $term->name );
}
}
// Add the imploded list of terms to the results content
if (!empty($list)) {
$r->content = implode( ', ', $list ) . '<br>' . $r->content;
}
}
}
return $results;
}