1

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!

3

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

1
  • $wp_query->query_vars is exactly what I asked for :) Thank you!
    – Camille V.
    Jun 8 '20 at 14:45
1

I believe you can use rewind_posts() to get the posts from the current query, then amend from there:

https://developer.wordpress.org/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.com/2011/09/3-ways-to-reset-the-wordpress-loop/

1
  • Thank you for your time, but it was not exactly what I was looking for (I was searching for current WP_query arguments)
    – Camille V.
    Jun 8 '20 at 14:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.