This website uses cookies to personalize your experience. By using this website you agree to our cookie policy.

Reply To: Force Uppercase Search

#27297
Ernest MarcinkoErnest Marcinko
Keymaster

Well, based on that code, I constructed this for you:

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' ) {
			// 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;
			}
		}

	}
}

Obviously I cannot test this, but it should add the imploded terms list to the beginning of the live results contents field.