-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Query statement has WHERE 1=1 instead of wp_postmeta.meta_value=1. #12
Comments
@laiconsulting I’ve seen that What’s the PHP code you’re using and the full SQL query it generates? |
The SQL query is
The only thing missing in the WHERE clause ps. It is a multisite setup. |
@laiconsulting it might be the location of the $arr_query = array(
- 'relation' => 'AND',
"meta_query" => array(
+ 'relation' => 'AND',
array(
"key" => "geom_line2__",
"compare_key" => "LIKE",
"compare" => "ST_INTERSECTS",
"value" => $geom_poly
),
array(
'key' => 'geom_point',
'compare' => 'EXISTS'
),
),
'posts_per_page' => -1,
'post_type' => 'post',
'post_status' => 'publish',
'order' => 'DESC',
'orderby' => 'date',
);
$withinbox_query = @(new WP_Query( $arr_query)); |
@andrewminion-luminfire Thanks for the suggestion. Looking at the SQL query, the |
@laiconsulting please take a look at the usage notes here for an example of how to use |
@andrewminion-luminfire If your concern is the Or do you mean something different when you meant taking a look at the example? |
Yes, I meant without the |
@andrewminion-luminfire Yes. |
Looks like this line should probably be checking that Maybe |
@andrewminion-luminfire The WHERE 1=1 piece is used so that all additional conditions can simply be appended with an "AND xxxx", "AND xxxx". Since there's already a known true value at the start, there's no need to figure out if we need to add an "AND" at the start of the next condition. This is especially useful when conditions are appended conditionally. |
Ok, I figured that out. The problem was 2 folds.
I needed this line, but it could not get into the WHERE cause because
|
@laiconsulting would you mind submitting that as a PR? |
The WP_Query statement is interpreted to have
WHERE 1=1
instead ofwp_postmeta.meta_value=1
. The result is that all posts are matched instead of those that satisfy the geospatial constraint.The text was updated successfully, but these errors were encountered: