admin管理员组

文章数量:1406717

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' );

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' );
Share Improve this question asked Oct 30, 2019 at 4:29 jsherkjsherk 1873 silver badges15 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

You can simply use $_SERVER['HTTP_REFERER']

If you prefer WordPress way, you can use wp_get_referer() function.

本文标签: plugin developmentHow do I find the pageurl where a search came from when using pregetposts filter