Query by meta key and order by another meta key value

You can do this with a meta_query. The get_posts() function accepts everything that WP_Query accepts so it could look something like this: $orders = get_posts( array( ‘numberofposts’ => -1, ‘posts_per_page’ => -1, ‘post_type’ => ‘executive-orders’, ‘orderby’ => ‘date’, ‘order’ => ‘DESC’, ‘meta_query’ => array( ‘relation’ => ‘AND’, ‘eo_type’ => array( ‘key’ => ‘eo_type’, ‘value’ => … Read more

WP_QUERY order posts by two combined meta_value dates

On post insert/update, set the post’s menu_order as the maximum of the numeric MMDD values of original_date and featured_date. Maybe set the menu order in the format 1MMDD to avoid a leading zero. Then we can order the custom type posts by the menu order very fast with: WP_Query( [ ‘post_type’ => ‘custom_post_type’, ‘orderby’ => … Read more