Passing conditional arrays to WP_Query() [closed]

Just build the static part of the args array, then add the conditional variables, then pass the args array to WP_Query(): // Static args $custom_query_args = array( /* static args here */ ); // Conditional arg if ( 1 == $promo ) { $custom_query_args[‘meta_query’] = array( /* meta query array */ ); } // Instantiate … Read more

Order by multiple meta keys on wordpress

I don’t understand why can’t you use the post_date of the custom post type which includes date and time together? $arg = array( ‘post_type’ => ‘custom_post_type’, ‘orderby’ => ‘post_date’, ‘order’ => ‘DESC’) $result = get_posts($args);

Custom Query With Multiple Meta Key Value

Try this: <?php $querydetails = ” SELECT wposts.* FROM $wpdb->posts wposts INNER JOIN ( SELECT post_id FROM $wpdb->postmeta wpostmeta WHERE ( ( wpostmeta.meta_key = ‘type’ AND wpostmeta.meta_value LIKE ‘%Collection1%’ ) OR ( wpostmeta.meta_key = ‘type’AND wpostmeta.meta_value LIKE ‘%Collection2%’ ) OR ( wpostmeta.meta_key = ‘type’AND wpostmeta.meta_value LIKE ‘%Collection3%’ ) OR ( wpostmeta.meta_key = ‘type’AND wpostmeta.meta_value LIKE … Read more

WP_Query and two custom fields returns no posts

The first query gives the expected results when the date format was corrected. $query = new WP_Query(array( ‘post_type’=>’games’, ‘orderby’=>’menu_order’, ‘order’=>’asc’, ‘posts_per_page’ => 1, ‘meta_query’=> array( ‘relation’=>’AND’, array( ‘key’=>’game_date_time’, ‘value’=>$nowtoday, ‘compare’ =>’>’ ), array( ‘key’=>’home_team’, ‘value’=>’Allen’, ‘compare’=>’LIKE’ ) ) ));