Reply To: Can't search cross network

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