Showing the post type name in result title or content
Displaying post type name in the live results title or content field

Post type name in title

1
add_filter( 'asp_results', 'asp_show_the_post_type_title', 10, 1 );
2
function asp_show_the_post_type_title( $results ) {
3
foreach ($results as $k=>&$r) {
4
if ( isset($r->post_type) ) {
5
// Modify the post title
6
$post_type_obj = get_post_type_object( $r->post_type );
7
$r->title = $post_type_obj->labels->singular_name . ' - ' . $r->title;
8
}
9
}
10
11
return $results;
12
}
Copied!

Post type name in content

1
add_filter( 'asp_results', 'asp_show_the_post_type_content', 10, 1 );
2
function asp_show_the_post_type_content( $results ) {
3
foreach ($results as $k=>&$r) {
4
if ( isset($r->post_type) ) {
5
// Modify the post title
6
$post_type_obj = get_post_type_object( $r->post_type );
7
$r->content = $post_type_obj->labels->singular_name . ' - ' . $r->content;
8
}
9
}
10
11
return $results;
12
}
Copied!
Last modified 3mo ago