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 8 years, 8 months ago.
- AuthorPosts
- December 17, 2015 at 9:29 am #7109
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
January 5, 2016 at 5:24 pm #7228Hi!
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 :)
- AuthorPosts
You must be logged in to reply to this topic.