This website uses cookies to personalize your experience. By using this website you agree to our cookie policy.

Forum Replies Created

Viewing 1 post (of 1 total)
  • Author
    Posts
  • in reply to: How to display Blog name with each result item #3083
    Shahbaz BadarShahbaz 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;
    }

Viewing 1 post (of 1 total)