admin管理员组文章数量:1278886
Context
I'm developping a plugin showing geolocated posts on a leaflet map. I want to add a shortcode parameter to show a map with only the current loop posts' markers. That feature would be great on the search result page for exemple!
Question
Is there a way to get the current page WP_Query arguments? I want to get those arguments to create a new WP_Query and add some more to filter only geolocated posts.
I don't know if it's possible at all, I always create new WP_query objects from scratch.
Thank you!
Context
I'm developping a plugin showing geolocated posts on a leaflet map. I want to add a shortcode parameter to show a map with only the current loop posts' markers. That feature would be great on the search result page for exemple!
Question
Is there a way to get the current page WP_Query arguments? I want to get those arguments to create a new WP_Query and add some more to filter only geolocated posts.
I don't know if it's possible at all, I always create new WP_query objects from scratch.
Thank you!
Share Improve this question asked Jun 5, 2020 at 15:21 Camille V.Camille V. 3291 gold badge2 silver badges12 bronze badges3 Answers
Reset to default 7Have you tried using $wp_query
?
global $wp_query;
var_dump($wp_query->query_vars);
For a single variable, you can use get_query_var
Or you could try just dumping the $_POST
, var_dump( $_POST );
Or maybe var_dump( $GLOBALS['post'] );
I believe you can use rewind_posts()
to get the posts from the current query, then amend from there:
https://developer.wordpress/reference/functions/rewind_posts/
This article has a good explanation of rewind_posts()
, differentiating it from wp_reset_postdata()
and wp_reset_query()
: https://digwp/2011/09/3-ways-to-reset-the-wordpress-loop/
Another alternative is to get it from the query
args directly. You can access all of the $args
this way.
$query = new WP_Query( $args );
// paged
$paged_arg = $query->query['paged'];
本文标签: wp queryHow to retrieve current page WPQuery arguments
版权声明:本文标题:wp query - How to retrieve current page WP_Query arguments? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741262750a2367922.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论