Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › How to display Blog name with each result item
This topic contains 2 replies, has 2 voices, and was last updated by Shahbaz Badar 9 years, 9 months ago.
- AuthorPosts
- November 25, 2014 at 3:31 pm #3037
Hello,
Unfortunately I can not provide you login info.
My only concern is: I want to to show Blog name with each result item displayed in search. Please look at this screenshot for understanding http://awesomescreenshot.com/0843wt0b7a.
Is there any way to achieve this?
Thank you.
November 26, 2014 at 11:21 am #3039Hi!
Ajax search pro offers numerous action and filter hooks. These hooks can be used to achieve such tasks. These actions/filters can be found in the actions.txt and filters.txt file. The asp_result_title_after_prostproc filter is what will possibly help.
Based on this knowledgebase article, I will try to implement some kind of solution: https://wp-dreams.com/knowledge-base/showing-the-post-type-name-in-post-title/
Try to paste this code to your themes functions.php file:
add_filter( "asp_result_title_after_prostproc", "asp_show_the_blog_title", 1, 1 ); function asp_show_the_blog_title( $title ) { $current_site = get_current_site(); return $current_site->site_name . " - " . $title; }
I have never tried this, but I think it will work.
Best,
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
December 3, 2014 at 5:56 am #3083Thank you for your reply.
By the way this code did not work for me as logic is wrong. Even logic used in reference post is wrong.
Following is updated code that will actually work.
add_filter( 'asp_pagepost_results', 'asp_show_the_post_type', 1, 1 );function asp_show_the_post_type( $pageposts ) {
foreach ($pageposts as $k=>$v) {$post_type = get_post_type( $pageposts[$k]->id );
// Modify the post title
$pageposts[$k]->title = $pageposts[$k]->title . ' - ' . get_site($pageposts[$k]->id) ;
}return $pageposts;
}function get_site($post_id) {
global $wpdb;
// Query all blogs from multi-site install
$blogs = $wpdb->get_results("SELECT blog_id,domain,path FROM wp_blogs where blog_id > 1 ORDER BY path");
$blogname = "";
foreach( $blogs as $blog ) {
$mypost = get_blog_post( $blog->blog_id, $post_id );
if(count($mypost)>0) {
if($mypost->post_status=="publish") {
$blogname = get_blog_option( $blog->blog_id, 'blogname' );
}
} else {
$blogname = get_blog_option( 1, 'blogname' );
}
}
return $blogname;
}
- AuthorPosts
You must be logged in to reply to this topic.