Reply To: How to display Blog name with each result item

Home Forums Product Support Forums Ajax Search Pro for WordPress Support How to display Blog name with each result item Reply To: How to display Blog name with each result item

#3083

Shahbaz Badar
Participant

Thank 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;
}