Can't search cross network

Home Forums Product Support Forums Ajax Search Pro for WordPress Support Can't search cross network

This topic contains 5 replies, has 2 voices, and was last updated by Ernest Marcinko Ernest Marcinko 7 years, 6 months ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #10284

    Anonymous

    The search only seems to return results from the current blog, not all of them.
    For instance, I created the page ‘space’ in my weddings blog site, but in the ‘estate’ blog page (the main blog) you cannot see the ‘space’ page in the results (but you can when searching on the weddings site).

    I’m tearing my hair out!!

    #10285
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi,

    Thank you for the details, I was able to identify the problem by logging-in onto your search dashboard. By default the plugin searches the currently active blog only, unless specified otherwise.

    I’ve selected the “Use all blogs” option on the Multisite options panel for you on both search instances. Now it should return results from both of your network sites as you expected: https://i.imgur.com/LqX9Hql.png

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #10292

    Anonymous

    Wonderful, thankyou.

    Once last question – is it possible to search only the PAGES from the current site but search POSTS and PAGES from a specified main site?

    Either this or ignore duplicates?

    #10293
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    You are welcome!

    Unfortunately that is not possible, the same search configuration applies for both sites.

    By duplicates you mean posts with the same titles on both sites? Because those are not actual duplicates in terms of the post objects, as multisite uses separate database tables to store the post type objects per site.

    One thing you can try, is to use this custom code to try to “filter” the duplicate titles post-search:

    1. Make sure to have a back-up of your site in case of any issues you can restore it.
    2. Try putting this anywhere into the functions.php file in your active theme directory (wp-content/themes/theme-name/functions.php file):

    add_filter('asp_pagepost_results', 'asp_try_filtering_dupe_titles', 1, 1);
    
    function asp_try_filtering_dupe_titles($results) {
      $new_res = array();
      $titles = array();
      
      foreach ($results as $r) {
        if ( !in_array($r->title, $titles) ) {
          $new_res[] = $r;
          $titles[] = $r->title;
        }
      }
    
      return $new_res;
    }

    This essentially checks if the object title is already in the results, if so then it’s not returned.

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #10294

    Anonymous

    Amazing! Which results would be the priority? Would it keep the post on the ‘main’ blog, or keep the result from the current domain?

    #10295
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    In this case this will just rotate through the results, first come, first stored.

    But since the search goes through each blog individually starting from the first one, then the results are sort of “grouped” before filtering, so it should prioritize the “main” aka. the first site in every case.

    In case you want to prioritize the currently active blog first, try this code instead:

    add_filter('asp_pagepost_results', 'asp_try_filtering_dupe_titles', 1, 1);
    
    function asp_try_filtering_dupe_titles($results) {
      $new_res = array();
      $titles = array();
      
      $current_blog = get_current_blog_id();
      
      // Move the results from the current blog first
      foreach ($results as $k => $r) {
        if ( $r->blogid == $current_blog ) {
          $new_res[] = $r; 
          $titles[] = $r->title; 
          unset($results[$k]);
        }
      }  
      
      // Check for duplicates whithin the rest
      foreach ($results as $r) {
        if ( !in_array($r->title, $titles) ) {
          $new_res[] = $r;
          $titles[] = $r->title;
        }
      }
    
      return $new_res;
    }

    I couldn’t actually test this one at the moment, but I believe it should do the trick, let’s hope 🙂

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


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

You must be logged in to reply to this topic.