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

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

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #10375
    atoohillatoohill
    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 MarcinkoErnest 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:

    [php]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;
    }[/php]

    This should do the trick 🙂

    #10401
    atoohillatoohill
    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.