Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $args = array(
- 'posts_per_page' => -1,
- 'post_type' => 'cpt_program',
- 'meta_query' => array(
- 'relation' => 'OR',
- 'ongoing' => array(
- 'key' => 'prog_ongoing',
- 'value' => 1
- ),
- 'start_date' => array(
- array(
- 'key' => 'prog_date_start',
- 'value' => date('Ymd'),
- 'type' => 'numeric',
- 'compare' => '>='
- )
- )
- ),
- 'orderby' => 'start_date ongoing',
- 'order' => 'ASC',
- );
- Returns this:
- Date: (1)
- Date: 04/10/15 (1)
- Date: (1)
- Date: (1)
- Date: (1)
- Date: 04/21/15 (1)
- Date: 06/11/15 (1)
- Date: (1)
- Date: 06/11/15 (1)
- Date: 06/23/15 ()
- Date: 06/30/15 ()
- I'm not sure what determines the order when the prog_date_start is not set?
- ===================
- Results I'd like:
- Date: 06/23/15 () // Not prog_ongoing comes first, ordered by prog_date_start
- Date: 06/30/15 ()
- Date: 04/10/15 (1) // prog_ongoing ordered by prog_date_start (those with set prog_date_start first)
- Date: 04/21/15 (1)
- Date: 06/11/15 (1)
- Date: (1) (all prog_ongoing without set prog_date_start at the end)
- ""
- ====================
- If I use the following I get real close.
- $meta_key1 = 'prog_ongoing';
- $meta_key2 = 'prog_date_start';
- $start_date = date('Ymd');
- $postids = $wpdb->get_col( $wpdb->prepare(
- "
- SELECT DISTINCT key1.post_id
- FROM $wpdb->postmeta key1
- INNER JOIN $wpdb->postmeta key2
- ON key2.post_id = key1.post_id
- AND key2.meta_key = %s
- WHERE key1.meta_key = %s
- AND key1.meta_value is TRUE
- OR key2.meta_value >= %d
- ORDER BY COALESCE(NULLIF(key1.meta_value, 0), 0) DESC, COALESCE(NULLIF(key2.meta_value, ''), $start_date) ASC, key2.meta_value ASC
- ",
- $meta_key2,
- $meta_key1,
- $start_date
- ) );
- Returns this:
- Date: 06/30/15 () // These top two are the problem. They don't order by prog_date_start. prog_ongoing equals 0 with these two.
- Date: 06/23/15 ()
- Date: 04/10/15 (1)
- Date: 04/21/15 (1)
- Date: 06/11/15 (1)
- Date: (1) (all prog_ongoing without set date at the end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement