Sort wp_query of two post types using meta datefield for one and date for the other – possible?

Try this WP_Query arguments: $args = array( ‘post__in’ => $all_ids, ‘meta_query’ => array( ‘relation’ => ‘OR’, array( ‘key’ => ‘_event_date’, ‘compare’ => ‘EXISTS’, ), array( ‘key’ => ‘_event_date’, ‘compare’ => ‘NOT EXISTS’, ‘value’ => ‘dummy_value’ // This is just to ensure this condition gets evaluated. ) ), ‘orderby’ => array( ‘meta_value_num’ => ‘DESC’, ‘date’ => … Read more

Meta query array – same order as specified order in value

Use PHP to sort the results after the query (untested): $product_ids = array( 3624, 1298, 430, 5629, 765 ); $query = new WP_Query( array( ‘meta_query’ => array( ‘relation’ => ‘AND’, array( ‘key’ => ‘product_id’, ‘value’ => $product_ids, ‘compare’ => ‘IN’, ), ), ) ); $posts_by_product_id = array(); $sorted_posts = array(); if ( $query->have_posts() ) { … Read more

new WP_Query with order args – no more distinction between categories

On the template driving your archive page, you can use the query_posts() function to adjust the main query (WordPress’ default main query, not your custom one). query_posts( array( ‘orderby’ => ‘modified’, ‘order’ => ‘ASC’, ) ); Using the pre_get_posts action is the better method, though slightly more complex (untested, would go in theme’s functions.php or … Read more

tech