Hey,
https://knowledgebase.ajaxsearchpro.com/hooks/filters/search-results/asp_cpt_results
I have a question about asp_cpt_results filter.
I am trying to get the s (Search Phrase) in $args in the function, but I can’t. How can I get the s (Search Phrase) in $args?
The following is a sample script from the above URL with $args[‘s’] added.
add_filter( 'asp_cpt_results', 'asp_cpt_result_filter', 10, 3 );
function asp_cpt_result_filter( $results, $search_id, $args ) {
$link = 'https://www.google.com/'; // Link to use, when not logged in
$link = $args['s']; // ADD
// 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;
}
Thanks in advance.
-
This topic was modified 3 years, 10 months ago by
.