wp-geo-posts
wp-geo-posts copied to clipboard
meta_query
Adding meta_query to the WP_GeoQuery class seems to break the query and no results are returned (if the lat and long values are entered):
$wp_query = new WP_GeoQuery(array( 'post_type' => array( 'locations' ), 'order' => 'DESC', 'orderby' => 'date', 'posts_per_page' => '12', 'paged' => $paged, 'meta_query' => array( array( 'key' => 'key_here', 'value' => 'yes', 'compare' => 'IN', ) ), 'latitude' => $lat, // User's Latitude (optional) 'longitude' => $lng, // User's Longitude (optional) 'radius' => 20, // Radius to select for in miles (optional) ));
any progress on this?
Hello, are others experiencing this problem? I've pinpointed the the issue and this seems to be when both a meta_query and radius is being used. If I take the radius away from the above query it works. So unfortunately as the meta_query is more important to us we're not able to use the radius at the moment.
Does anyone know what may be causing this?
After enabling WP debug I've found out that there was an SQL error when both meta_query and the radius was enabled.
The issue seems to be with GROUP BY in the sql command. This is what breaks the query when the radius is entered. And as GROUP BY is only added when a taxonomy_query or meta_query is present the two together (meta_query and radius) are causing the problem.
I used the posts_groupby filter (http://codex.wordpress.org/Plugin_API/Filter_Reference/posts_groupby) to remove the GROUP BY. I added the following to line 139 of geo-query.php and everything seems to be working well now:
function posts_groupby($groupby) { $groupby = false; return $groupby; }
I called the function by adding the following to line 41:
add_filter('posts_groupby', array(&$this, 'posts_groupby'), 10, 2);
Thanks! I came across this same issue and the filter fixed it for me too.
Yay! It solved my issue too! In my case, it wasn't meta_query which was used, but category ID.
Thanks a lot!