Including Taxonomy Name next to Terms in Results

Home Forums Product Support Forums Ajax Search Pro for WordPress Support Including Taxonomy Name next to Terms in Results

This topic contains 2 replies, has 2 voices, and was last updated by atoohill atoohill 7 years, 6 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #10375
    atoohill
    atoohill
    Participant

    When taxonomy terms are returned as results is there a way to include the taxonomy name next to the taxonomy term? Example, I have a taxonomy name “Speaker”. When the results return it would be nice for it to look like this: “Speaker – Speaker Name”, instead of just “Speaker”. Is there a function or something in the settings I’m not seeing that would make this possible? It’d be incredibly useful for us. Thank-you.

    #10383
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi!

    Yes, actually it is possible. I’ve put together a small code snippet for you, put it in the functions.php file in your active theme directory:

    add_filter( 'asp_results', 'asp_taxonomy_names_in_terms', 1, 1 );
     
    function asp_taxonomy_names_in_terms( $results ) {
      foreach ($results as $k=>$v) {
        if ( $v->content_type == 'term' ) {
          $t = get_taxonomy( $v->taxonomy );
          if ( !is_wp_error($t) )
            $results[$k]->title  = $t->label . ' - ' . $results[$k]->title;
        }
      }
     
      return $results;
    }

    This should do the trick 🙂

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #10401
    atoohill
    atoohill
    Participant

    Hey, that did the trick, thanks so much!

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.