plugin development - How do I find the pageurl where a search came from when using pre_get_posts filter?

When I use pre_get_posts filter, I want to check what urlpage the search query came from, but the $query var does not a

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745044111a4607989.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信