Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › How to change the results URL to something else based on the different page id
This topic contains 3 replies, has 2 voices, and was last updated by Ernest Marcinko 3 years, 1 month ago.
- AuthorPosts
- May 6, 2020 at 2:55 pm #27142
Hi,
I have tried to change the results URL based on the page URL parameters. eg. $_GET[‘page_id’] may I know how do modify the code but I can’t get any value after I have do some modification.
Please advice.
add_filter( ‘asp_results’, ‘asp_custom_link_results’, 1, 1 );
$page_id = $_GET[‘page_id’];
function asp_custom_link_results( $results ) {
global $page_id;
// Parse through each result item
foreach ($results as $k=>$v) {
/**
* In this context the
* $results[$k]->link
* variable holds the result link. Make modifications to that variable.
*/
$results[$k]->link = ‘https://google.com’.$page_id;
}return $results;
}May 6, 2020 at 3:16 pm #27144Hi,
The $_GET[‘page_id’] is not available in that context, because that is an ajax request. However, the search arguments do include this:
Best,add_filter( 'asp_results', 'asp_custom_link_results', 10, 4 ); function asp_custom_link_results( $results, $id, $is_ajax, $args ) { foreach ($results as $k=>&$r) { $r->link = 'https://google.com' . $args['_page_id']; } return $results; }
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
May 6, 2020 at 3:25 pm #27146Hi,
Thanks for the reply, just to checking $args[‘_page_id’] is pull the current page id? May I know is that anyway we can pull the previous page id? Because I will need to click the result link to redirect back to the previous page.
May 6, 2020 at 3:28 pm #27147Yes, that gives the page ID from where the search was initiated. Unfortunately I don’t think that is possible at all. Usually the information is lost during redirection.
Best,
There might be a way to somehow get that via server variables, but those probably won’t work in the ajax context. As in that case the previous page (referrer) is actually the page the search is on.
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
- AuthorPosts
You must be logged in to reply to this topic.