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

Reply To: Force Uppercase Search

#27290
humblehumans86humblehumans86
Participant

Ernest ,

This might be a bit of a stretch but its worth an ask. In any event appreciate all the help thus far.

Our site has two types of searches, one in the header powered by ASP and an inline page search powered by a combination of possbile of input queries. As it relates to the original task of displaying Taxonomy Terms of said search results I was able to replicate the behavior on both. So for that alone thank you again!

Furthermore I was able to implement a hierarchical display of taxonomy terms relative to each search result but with a bit of a performance loss. So instead I altered my ask and was hoping you could point me in the right direction to replicate with ASP.

Essentially I have a function in my functions.php file that accepted two parameters, a post ID and Name (though the function could determine Name, I just had value stored when I was calling function). Based on that it generates the following taxonomy terms but prevents terms from displaying based on the following criteria.

A. Taxonomy Term is the same value as the Post Title
B. Taxonomy Term is a Parent Term
c. Taxonomy Term is already being displayed and within our Term array

How would you recommend achieving similar result with ASP as this function only addresses our inline page search? For instance assuming I need the ‘asp_results” filter but unable to determine exactly what is being passed off in $results. Below is the function i’m using to accomplish this task with my non-ASP search.


function search_result_interchange($product_name, $product_id) {

  // Get Taxonomy Term IDs based on Post ID of Search Result
  $term_ids = wp_get_post_terms( $product_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 );
    }
  }

  // If no unique Terms Names are found display Post Name
  if (!empty($list)) {
    echo implode( ', ', $list );
  } else {
    echo $product_name;
  }

}