asp_only_non_keyword_results

Gives access the results array before sending it to the templating system.

Gives access the results array before sending it to the templating system. Different from asp_results, as this is only applied in ajax context, when any results were found, and no keyword suggestions are enabled.

apply_filters('asp_only_non_keyword_results', $results, $search_id, $phrase, $args);

Parameters

  • $results (array) - Array containing the result objects.

  • $search_id (int) - Search instance ID

  • $phrase(string) - The search phrase

  • $args (array) - Search arguments

Usage

add_filter( 'asp_only_non_keyword_results', 'asp_custom_link_results', 10, 4 );
function asp_custom_link_results( $results, $search_id, $phrase, $args ) {
	$link = 'https://www.google.com/';	// Link to use, when not logged in
	
	// Parse through each result item
	foreach ($results as $k=>&$r) {
		/**
		 * $r (stdClass object) {
		 *      'id' -> Post or other result object (taxonomy term, user etc..) ID,
     *      'title' -> Result title
     *      'content' -> Result content
     *      'post_type' -> Result post type (if available)
     *      'content_type' -> Content type (pagepost, user, term, attachment etc..)
		 * }
		 **/
		if ( !is_user_logged_in() )
	  	$r->link = $link;
	}

	return $results;
}

Last updated

Copyright Ernest Marcinko