Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › How to display custom post category on results
This topic contains 3 replies, has 2 voices, and was last updated by Ernest Marcinko 6 years, 11 months ago.
- AuthorPosts
- October 20, 2016 at 9:56 am #10538
Hi, I have a few custom posts and would like to display the custom categories for those posts in the results. I found this code but doesnt seem to be working for me (see below)
The name of the category is ‘venues-category’.
Also in the Advanced Title Field what would I need to type to show the category? {venues-category} ?
add_filter( ‘asp_pagepost_results’, ‘asp_add_category_titles’, 1, 1 );
function asp_add_category_titles( $pageposts ) {
foreach ($pageposts as $k=>$v) {// Get the post categories
$post_categories = wp_get_post_categories( $pageposts[$k]->id );
$cats = “”;// Concatenate category names to the $cats variable
foreach($post_categories as $c){
$cat = get_category( $c );
$cats = ” “.$cat->name;
}// Modify the post title
$pageposts[$k]->title .= ” “.$cats;
}return $pageposts;
}October 20, 2016 at 10:36 am #10543Hi,
Yeah, that code will only work with posts and categories, try this one instead:
Best,
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
October 20, 2016 at 11:00 am #10544Thank you Ernest. What do I need to type to display it in the Advanced Title Field section? e.g. {Venues-category} ?
October 20, 2016 at 12:01 pm #10545Hi,
You don’t have to type there anything, this is a post processing function, it’s executed after the advanced fields are processed.
Best,
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
- AuthorPosts
The topic ‘How to display custom post category on results’ is closed to new replies.