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

Use both meta query and tax query

Would you believe it, as soon as I posted this I remembered I asked a question about a query last year. I had a look over it and I’ve adapted my new query like so: $category_slug = filter_input( INPUT_GET, ‘eventtype’, FILTER_SANITIZE_STRING ); $cat_query = []; if( $event_type ){ $cat_query = [ [ ‘taxonomy’ => ‘eventtype’, … Read more

How to filter posts by specific date and its tag

Ashur Please try following code with date_query. this is working fine at my end. Let me know if you want any additional detail. <?php $postdate = get_the_date(‘Y-m-d’); $args = array( ‘posts_per_page’ => -1, ‘post_type’ => ‘post’, ‘date_query’ => array( ‘after’ => $postdate, ) ); $update = new WP_Query($args); while ($update->have_posts()) { $update->the_post(); $post_id = get_the_ID(); … Read more

meta_query for a string inside a meta field containing a comma-separated list

Is there a smart way to meta_query so it matches just “IS, but not “TS-IS”? The WordPress meta query class (WP_Meta_Query), which among others, is used with the posts (WP_Query) and users (WP_User_Query) query classes, supports REGEXP (since WordPress 3.7) as the compare value, so you could use that with a RegEx (regular expresion) pattern … Read more

Display no post when metavalue is 0

Here’s an updated example that appears to do what you want. See the docs for meta queries for details. $query_args = [ ‘post_type’ => ‘list’, ‘posts_per_page’ => 3, ‘orderby’ => ‘meta_value_num’, ‘order’ => ‘DESC’, ‘meta_query’ => [ [ ‘key’ => ‘post_views_count’, ‘value’ => 50, ‘compare’ => ‘>’, ‘type’ => ‘NUMERIC’, ], ], ]; $post_views_query = … Read more