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

This topic contains 3 replies, has 2 voices, and was last updated by Ernest Marcinko Ernest Marcinko 2 years, 5 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #27142
    kaalwei8324
    kaalwei8324
    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 Marcinko
    Ernest 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;
    }
    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #27146
    kaalwei8324
    kaalwei8324
    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 Marcinko
    Ernest 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.

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.