How do I find the page/url where a search came from when using pre_get_posts filter?


When I use pre_get_posts filter, I want to check what url/page the search query came from, but the $query var does not appear to contain that information.

How do I retreive it in my function below?

function my_custom_search_results($query) {
    if ( is_search() && $query->is_main_query() ) {
        // How do I check the page/url of this search for where it came from?
    return $query;
add_filter( 'pre_get_posts','my_custom_search_results' );
jsherk 3 years 2019-10-29T23:29:30-05:00 0 Answers 91 views 0

Leave an answer