Have you var_dump
ed $location
?
WP_Query
‘s meta_query
uses the class WP_Meta_Query
, which automatically appends and prepends ‘%’ to any string passed to it:
// From wp-includes/class-wp-meta-query.php:610
switch ( $meta_compare ) {
// ...
case 'LIKE' :
case 'NOT LIKE' :
$meta_value="%" . $wpdb->esc_like( $meta_value ) . '%';
$where = $wpdb->prepare( '%s', $meta_value );
break;
// ...
}
So maybe try using (string) $location
as the sql statement is prepared, and expecting a string — that’s what the %s
means in the line $where = $wpdb->prepare( '%s', $meta_value );
. You can cast your variable to a string like this:
$location = (string) preg_replace('/^-|-$|[^-a-zA-Z0-9]/', '', $_GET['location']);
Related Posts:
- How to do a meta query using REST-API in WordPress 4.7+?
- Meta query terribly slow
- meta_query sorting by 2 keys
- Get result from meta_query() between two numbers
- How to handle optional end date in compare clause in meta_query
- Using meta_query on pre_get_posts to exclude a particular meta_key value
- Best practice – Meta Query vs. post_clauses for “left join” ordering
- Different page parameters inside query
- Return posts with specific meta key first, but the rest in alpha order by last name
- meta_query key value from array
- LIKE %…% Meta Query
- Order by nested named meta queries with ‘exists’ and ‘not exists’
- Documentation for post meta
- Arrange Posts By Date In Order Of Closest To The Current Date
- Custom Upcoming Events List for Events Manager Plugin
- How to use meta_query to check if a meta field has something set?
- How to exlude posts that have certain meta_value?
- User Relationship
- How to make a WP REST API query with meta_query in WP4.7?
- WordPress Core – Optimizing meta_query generated SQL?
- Edit post_content on posts with Featured Image
- Use both meta query and tax query
- meta_query, number comparison, not quite working as it should
- Query posts only if meta_value is not empty
- Does meta_query working with value paramater higher then 999?
- How to pass user meta_key and meta_value (values as array)
- meta_query compare=’!=’ with multiple custom fields
- Query posts with numeric meta values within a given range
- Fastest way to do meta query when I don’t need the actual posts, and just need post_id?
- meta_query not working on live site
- How to query post only with different excerpt?
- How do you get Posts by multiple meta_keys and meta_values with the Rest API V2?
- Meta query with regular expression does not work
- WP User Query Issues
- How to use meta query for greater than value in array?
- Wp Query custom search by meta query
- Filter posts by meta query?
- Help on multiple meta_query
- Meta query – How to display a null meta key
- pre_get_posts and set
- Meta query date column add [x] days to validate
- How to use orderby with meta_query?
- Orderby doesn’t work like expected on custom query
- last_name + first_name orderby with meta_query [solved]
- Extend meta query arguments
- get_posts( $args ) return empty data
- how to get post meta where value is an array of key value pairs
- Meta Query Based on Month Range
- how to search all user meta data that have value like “vivek”
- Find posts by related taxonomy field
- wordpress meta value compare between two date
- Can I use pre_get_posts to add up values from two different meta_keys?
- WP JSON API meta_query not working
- get_users with Serialized Custom Meta Value
- Sorting posts by ACF field
- Ordering custom posts by meta field date
- latitude/longitude meta_query
- meta_query displays all results and none, my query is wrong
- How to properly escape values in meta query
- Delete all posts with a specific custom field using meta_query
- Fetch custom post related to a User
- How to Ordering by user meta
- Use meta_query in args for relationship
- meta_query Array
- meta_query compare “=“ returns nothing when it seems it should
- Order resultset by configured value and then list all the rest
- Issue with user meta_query
- How to get an archive page meta?
- Search for value(s) in meta field for a multi select
- Querying terms with calculations based on term meta data, sql vs. get_terms
- How can I create a meta_query with an array of dates?
- WordPress meta query not working
- Get meta_value from GDRating
- wordpress meta query with multiple meta condition causing a load on server and slows down the server..!
- Why does this incorrect pre_get_posts meta_query work for sort order?
- How to sort custom posts including null meta-values in admin columns with meta_query?
- Memory Leak in Processing Large JSON file
- meta_query not filering but meta_key works fine
- get posts meta query returning the latest post if no meta key found
- WordPress search between two newmeric values with a custom post type
- WP User Query with meta queries
- Search using specific meta fields only (excluding post title and content)
- How to fetch WP_User_Query with multiple role arguments [duplicate]
- How to get meta value based on latest post id with group by term name
- Meta query not returning results even though the sql contains the information
- Display Users from two roles in one list
- WP_Query with UNIX timestamp in meta query
- Querying by meta key and value
- Multiple Queries with meta_query
- Get foreach for meta_query value
- Sort posts by post views and consider meta key
- Meta query “OR” comparison not working as expected with array
- order by meta_key [duplicate]
- Meta query with string NOT ending like pattern
- ACF meta_query field treated as “0” resulting in false negative search when testing ranges
- acf/save_post affecting WP_Query results
- Merge meta_value’s into a single row and then loop
- Is it possible to customize meta query in this way?
- How making a new search box in admin post table working on a specific column
- wp_user_query with meta_value_num for leaderboard