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 badges
Add a comment  | 

3 Answers 3

Reset to default 7

Have 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