asp_results
Let's you access the results array before sending it to the templating system.
Let's you access and modify the results array before sending it to the templating system or the results page.
1
apply_filters('asp_results', array $results, int $search_id, bool $is_ajax, array $args);
Copied!

Parameters

  • $results (array) - Array containing the result objects.
  • $search_id (int) - Search instance ID
  • $is_ajax (bool) - Is the current request an ajax search
  • $args (array) - Search arguments

Usage

1
add_filter( 'asp_results', 'asp_custom_link_results', 10, 1 );
2
function asp_custom_link_results( $results ) {
3
$link = 'https://www.google.com/'; // Link to use, when not logged in
4
5
// Parse through each result item
6
foreach ($results as $k=>&$r) {
7
/**
8
* $r (stdClass object) {
9
* 'id' -> Post or other result object (taxonomy term, user etc..) ID,
10
* 'title' -> Result title
11
* 'content' -> Result content
12
* 'image' -> Result image URL
13
* 'post_type' -> Result post type (if available)
14
* 'content_type' -> Content type (pagepost, user, term, attachment etc..)
15
* }
16
**/
17
if ( !is_user_logged_in() )
18
$r->link = $link;
19
}
20
21
return $results;
22
}
Copied!
Copy link