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

This topic contains 2 replies, has 2 voices, and was last updated by Shahbaz Badar Shahbaz Badar 9 years, 4 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #3037
    Shahbaz Badar
    Shahbaz Badar
    Participant

    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.

    #3039
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi!

    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 :)


    #3083
    Shahbaz Badar
    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;
    }

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.