As I said, I was just missing the declaration to use the global $wp_query, so it wasn’t accessing my filters.
Here’s what worked incase it helps:
global $wp_query;
// pull variable from url
if (isset($wp_query->query_vars['country']))
{
$this->user_country = $wp_query->query_vars['country'];
}
else { $this->user_country = 'your country'; }
if (isset($wp_query->query_vars['lat']))
{
$this->user_lat = $wp_query->query_vars['lat'];
}
else { $this->user_lat="52.5"; }
if (isset($wp_query->query_vars['lon']))
{
$this->user_lon = $wp_query->query_vars['lon'];
}
else { $this->user_lon = '13.4'; }
Related Posts:
- Is there a way to extend WP_query so Custom Post Types can have properties?
- paginate_links ignore my format
- How to add multiple custom URL variables?
- Query two taxonomies via URL or link?
- Calling a wp_query $posts causes a 500 error
- How to capture a variable query string, then append it to all URLs in a WordPress site
- How do you Query posts with nothing in common?
- WP_Query Variable inside Array
- Changing WP_Query params with url Query Var
- Use post object from first query in second query
- Excluding pages in WP_query using ACF
- WP_Query Attachment adds additional attachment count and need to link attachment to post url
- Assign custom parameter to each post in query
- WordPress Query String: get_posts(‘cat=5’) vs WP_Query( ‘cat=5’) vs URL: /site/?cat=5
- how to load posts to a custom post template after using template_redirect or template_include
- Custom Taxonomy Archive Page to display either ALL listings or only from URL
- Form checkbox value going to dynamic URL
- URL to Post Archive of Custom Query
- Get specific value from variable to use in query
- Using URL variables on a custom WP_Query
- How can I display a specific number of post in a category via a url
- WP_Query orderby date not working
- Best way to detect if you are in a SINGLE POST page
- How to do a wp_query using “BETWEEN” with two meta_values?
- Better way to get tag stats?
- wp_query order by title
- Sort posts by custom taxonomy name
- Wp_query order by multiple custom fields?
- Would this post meta be better added to the post table rather than post_meta table
- meta_query on a date range using an array of values
- How to exclude products by tag from woocommerce shop page?
- Filtering posts by custom field value not working
- wpdb get results doesn’t work with variable
- Query Ignoring ‘exclude’ Parameter?
- Custom pagination with WP_Query generating 404 error
- Query post with meta_query where date is not in future
- Apply CSS class to every second database record [closed]
- How to prevent writing duplicate loops?
- merge two query arguments into one WP_Query call
- Adding a parameter to the default query
- Using WP_Query in “parse_query” or “pre_get_post” in Posts2Posts
- Taxonomy search/filter with multiple taxonomies and multiple taxonomy terms
- How do I change the order (ASC and DESC) in the following retrieval method using WP_Query?
- While creating Block Themes in WordPress, how can I query custom posts for an Archive view?
- How To Fix WP Query Returns Results But Shouldn’t?
- Weird orderby => post__in issue
- How to extract specific post
- wp_Qwery works to slow
- Custom post type archive pagination query issue
- 2 weeks ago from meta query meta value
- WP Group posts by year(desc) > month(desc) > date(asc)
- Running main loop 2 times with conditional statement
- paged variable not working for category/custom post archive
- Array as ‘key’ in WP_Query
- Check the Specific Meta Key IF its Meta Value is Empty then… (WP Post Meta Query)
- Searching for meta_key returns 0 posts
- Using custom taxonomies in a query
- Determining Author post count
- How I can change the condition or compare operator for WP_Query in pre_get_posts
- Apply filters to main query instead of creating new one?
- WP_Query returns different results from get_posts() [closed]
- How to pass query string vars between admin pages?
- Query posts by Post title
- mysql query order by
- Why do I have to use pre_get_posts with custom WP_Query to reset posts_per_page?
- Query to get last posts from authors of blog
- Custom Homepage Pagination using WP_Query
- My website is getting too many dierect home arechives and this is increasing my bounce rate
- How to get latest post excerpt from a specific category?
- Get all content on a “single page” site depending on language
- Get list of all Grandchild Pages
- get latest added term from taxonomy and insert into php variable
- Featured images loop for Orbit Slider
- WP_Query return posts in wrong order
- Unable to display multiple parameters from url by javascript through shortcodes
- How do i create a custom post query when the meta value is an array?
- How to do WP_User_Query for Nested Array value Inside Nested Array field
- Display the search results like the original pages
- Pagination on archive.php not working?
- How to use jQuery validation to set the search bar to accept only a specific input?
- How to filter on placeholder image
- How to compare between two dates in a nested loop?
- How to query 5 users in random who have published more than 10 posts
- WP query for two post types how to order newest to oldest with two different meta fields?
- Order & Orderby clause not working with custom query
- WP_Query doesn’t works inside loop
- How to redirect a query string to a “virtual” subdirectory
- WP_Query returns images but post_per_page is incorrect
- WP_Query with child element
- Select posts wich has no relationship in custom taxonomy
- WordPress Query posts that have title > another title
- Custom query to order by multiple taxonomies
- Different sql queries count indicator on the main page [closed]
- Query Posts to fetch Posts with Unique Tag
- WP_Query issues with argument posts_per_page
- Search (Custom Form, Custom Search Result)
- Elementor custom query
- How do I subquery with custom meta fields?
- Show number of posts AND number on current page (cannot make it work)
- Advanced Search – Is this possible?