WP_user_query throws a 404 error

pre_user_query is called after the query variable object is created, but before the actual query is run. Your code is creating a new query within the action when you should actually modify the existing query’s arguments using the $query->set() method. For example: function my_pre_user_search($user_query) { $meta_query = array(array( ‘key’ => ‘member_id’, ‘value’ => ‘2349’ )); … Read more

Meta query with a sub query group possible?

I don’t think you need the relation parameter. It defaults to AND. $nowtime = time(); $the_query = new WP_Query( array( ‘post_type’ => ‘promos’, ‘orderby’ => ‘menu_order’, ‘order’ => ‘ASC’, ‘meta_query’ => array( array( ‘key’ => ‘wpcf-type-of-promo’, ‘value’ => ‘walls’, ‘compare’ => ‘NOT LIKE’ ), array( ‘key’ => ‘wpcf-date-and-time-start’, ‘value’ => $nowtime, ‘compare’ => ‘<‘, ‘type’ … Read more

Comparing a field with several values at once with meta_query

The parameter ‘meta_query’ is an array, so you can add multiple meta keys. In the doc, below the section “Example: Multiple Meta Entries – Multi dimensional array”, you can find an example where the relation is set to ‘OR’: $query_args = array( ‘meta_query’ => array( ‘relation’ => ‘OR’, array( ‘key’ => ‘foo_key’, // ‘value’ => … Read more

Custom post type archive with rand and meta_value

You could use the ‘posts_orderby’ filter: function custom_loops($query) { if ( is_post_type_archive(‘my_post_type’) ){ $query->set( ‘posts_per_page’, 40); $query->set( ‘meta_key’, ‘custom_meta_sponsored’); $query->set( ‘orderby’, ‘custom_meta_sponsored’); $query->set( ‘order’, ‘DESC’); add_filter( ‘posts_orderby’, function ( $orderby, $query ) { if ( $query->get( ‘orderby’ ) != ‘custom_meta_sponsored’ ) return $orderby; global $wpdb; $orderby = $wpdb->prepare( ‘CASE WHEN ‘ . $wpdb->postmeta . ‘.meta_value … Read more

Any number in meta key (wp query)

You must use LIKE on the meta_key to support the SQL % pattern. The compare attribute only applies to the meta value. Instead you could try to filter it with: /** * Match any numbers in given a meta-key for WP_Query * * @see https://wordpress.stackexchange.com/a/177331/26350 */ ! is_admin() && add_filter( ‘posts_where’, function( $where ) { … Read more

Query posts if meta key starts with

I figured it out: $the_query = new WP_Query(array( “numberposts” => -1, “post_type” => “plays_events”, “meta_query” => array( array( “key” => “show_times_%_date”, “value” => $this_month . “[0-9]{2}”, “compare” => “REGEXP” ) ), ));

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