meta_query, number comparison, not quite working as it should

Firstly, there’s no point in converting to ‘meta_query’ if you’re dealing with a single custom field. Secondly, ‘meta_query’ doesn’t handle ordering. Finally, since your date is in the ‘Ymd’ format, comparing them as numbers will produce incorrect results. In your initial code, they are compared as strings.

Creating arguments from loop for WP_Query meta_query

How about this? /** * Convert query string to meta query. */ function query_string_to_meta_query( $query_string ) { $meta_query = array( ‘relation’ => ‘AND’ ); foreach ( wp_parse_args( $query_string ) as $key => $value ) { $meta_query[] = array( ‘key’ => $key, ‘value’ => $value ); } return array( ‘post_type’ => array( ‘post’, ‘custom’ ), ‘meta_query’ … Read more

Query that joins the postmeta table twice

“My SQL doesn’t work” questions are difficult because they are nearly untestable without having the OP’s dataset, but… I think you may be making this too complicated. SELECT DISTINCT (p.ID), p.post_title FROM wp_posts p JOIN wp_postmeta pm1 ON p.ID = pm1.post_id JOIN wp_postmeta pm2 ON p.ID = pm2.post_id WHERE 1 = 1 AND p.post_type=”game” AND … Read more

How to orderby meta_value_num with dollar ($) sign

You could also use the posts_orderby filter: function wpse155827_posts_orderby_price( $orderby ) { return str_replace( ‘wp_postmeta.meta_value’, ‘substr(wp_postmeta.meta_value, 1)’, $orderby ); } add_filter( ‘posts_orderby’, ‘wpse155827_posts_orderby_price’ ); $theQuery = new WP_Query( array( ‘orderby’ => ‘meta_value_num’, ‘meta_key’ => ‘price’, ‘order’ => ‘ASC’, ‘suppress_filters’ => false, ) ); remove_filter( ‘posts_orderby’, ‘wpse155827_posts_orderby_price’ );

What format does the meta_query TIME type require?

Date and time format meta_query requires the same format you used when storing the data of the meta fields. Some times different formats can be compared directly, but most of the time they aren’t. A recommend format to use is MySQL format: date format: YYYY-MM-DD (for PHP date functions: Y-m-d) time format: HH:MM:SS (for PHP … Read more

Meta query with JSON value

That’s not json. You can’t put a semi-colon inside a javaScript Object like that. That’s serialized-data. If you return that string & then call unserialize on it & then var_dump you can see what’s inside. Also, see fuxia♦’s Answer Here for more info. & to Maikal’s credit, you can use a meta_query in this situation, … Read more

Wildcard with LIKE operator in Meta query

Have you var_dumped $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; // … … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)