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
1 Answer
Reset to default 1You 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条)