Taxonomies as search results

Home Forums Product Support Forums Ajax Search Pro for WordPress Support Taxonomies as search results

This topic contains 1 reply, has 2 voices, and was last updated by Ernest Marcinko Ernest Marcinko 8 years, 3 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #7109
    kkmarch7
    kkmarch7
    Participant

    Hi

    Is it possible to have certain taxonomies appear in the search results box as opposed to “content’?

    My search is set to search posts and I would like to have the taxonomies attached to the posts appear in the search results box.

    The Search Results would include the post image, the post title and the taxonomies for the post.

    I have it set to the Vertical layout.

    Thank You

    #7228
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi!

    I’m sorry, I’ve missed your ticket by accident.

    It’s unfortunately not possible, there is not setting for this type of display. However based on this knowledge base article, you can try this code:

    add_filter( 'asp_pagepost_results', 'asp_add_term_titles', 1, 1 );
     
    function asp_add_term_titles( $pageposts ) {
      foreach ($pageposts as $k=>$v) {
        // Change this to the taxonomy name you want to use
        $taxonomy = "my_taxonomy";
     
        // Get the taxonomy terms
        $post_terms = wp_get_post_terms( $pageposts[$k]->id, $taxonomy );
        $terms = array();
     
        // Concatenate term names to the $cats variable
        foreach($post_terms as $t){
            if ( !empty($t->name) )
              $terms[] = $t->name;
        }                
     
        // Modify the post content
        if ( !empty($t) )
          $pageposts[$k]->content  = implode(", ", $t);
      }
     
      return $pageposts;
    }

    Try adding this code in your active theme directory to the functions.php file. Then change the $taxonomy variable from “my_taxonomy” to the taxonomy you want to use.

    Best,
    Ernest Marcinko

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


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

You must be logged in to reply to this topic.