Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › display cpt AND custom Taxonomy next to post title in results page › Reply To: display cpt AND custom Taxonomy next to post title in results page
August 15, 2020 at 12:55 pm
#28973
Keymaster
Well, you can check the $r->taxonomy variable it it exists, if so, then the current result is a taxonomy term:
add_filter( 'asp_results', 'asp_show_the_more_info', 10, 1 );
function asp_show_the_more_info( $results ) {
foreach ($results as $k=>&$r) {
if ( isset($r->post_type) ) {
// Modify the post type post title
$r->title = get_post_type( $r->id ) . ' - ' . $r->title;
} else if ( isset($r->taxonomy) ) {
// Modify the taxonomy term type post title
$term = get_term( $r->id );
$r->title = $term->taxonomy . ' - ' . $r->title;
}
}
return $results;
}
This will print the taxonomy name or the post type name before the result.