WP_Query order
-
Hello, I’m trying to order a WP_Query. I currently have it working – ordering a list of personnel by custom fields (group, rank) and post date. This is working a treat with one exception. The post date is actually date of hire which is fine, but I have another custom field for promotion date and need to order by that field first, then by post date. I’m at a complete loss here. Here is my current code:
// Query Arguments to order posts by Group, Rank, and Seniority
$args = array(
'post_type' => 'personnel ',
'posts_per_page' => -1,
'meta_query' => array(
'relation' => 'AND',
'group_clause' => array (
'key' => 'group',
'value' => 'Resigned/Retired/LODD',
'compare' => '!=',
),
'rank_clause' => array(
'key' => 'rank',
'compare' => 'EXISTS',
),
),
'orderby' => array(
'group_clause' => 'ASC',
'rank_clause' => 'DESC',
'date' => 'ASC',
),
);
// Query the database
$loop = new WP_Query( $args );I’ve tried adding promotion_clause => array but I need to include all the posts – even those without a promotion date. Is there a way to order by promotion date first if it exists, then by post date?
Thanks in advance
The page I need help with: [log in to see the link]
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- You must be logged in to reply to this topic.