This website uses cookies to personalize your experience. By using this website you agree to our cookie policy.

How to change the results URL to something else based on the different page id

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

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #27142
    kaalwei8324kaalwei8324
    Participant

    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;
    }

    #27144
    Ernest MarcinkoErnest Marcinko
    Keymaster

    Hi,

    The $_GET[‘page_id’] is not available in that context, because that is an ajax request. However, the search arguments do include this:

    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;
    }
    #27146
    kaalwei8324kaalwei8324
    Participant

    Hi,

    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.

    #27147
    Ernest MarcinkoErnest Marcinko
    Keymaster

    Yes, 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.
    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.

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.