SHARE
TWEET

Untitled

a guest Jul 7th, 2015 208 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  $args = array(
  2.         'posts_per_page' => -1,
  3.         'post_type' => 'cpt_program',
  4.  
  5.         'meta_query' => array(
  6.             array(
  7.             'relation' => 'OR',
  8.                 array (
  9.                     'key' => 'prog_ongoing',
  10.                     'value' => true,
  11.                     'compare' => '=',
  12.                 ),
  13.                    
  14.                 array (
  15.                     'key' => 'prog_date_start',
  16.                     'value' => date('Ymd'),
  17.                     'compare' => '>=',
  18.                 ),
  19.             ),
  20.         ),
  21.  
  22.         'orderby' => 'prog_date_start',
  23.         'order'   => 'ASC',
  24.     );
  25.  
  26. // posts_orderby filter
  27.  
  28. function order_by_custom_fields( $orderby ){
  29.     $start_date = date('Ymd');
  30.     global $wpdb;
  31.     if( ! is_admin() ) :
  32.     $orderby =
  33.         "CASE
  34.            WHEN {$wpdb->prefix}postmeta.meta_key = 'prog_date_start' AND {$wpdb->prefix}postmeta.meta_value >= $start_date THEN '1'
  35.            WHEN ({$wpdb->prefix}postmeta.meta_key = 'prog_ongoing' AND {$wpdb->prefix}postmeta.meta_value) AND ({$wpdb->prefix}postmeta.meta_key = 'prog_date_start' AND {$wpdb->prefix}postmeta.meta_value) THEN '2'
  36.        END DESC";
  37.     endif;
  38.     return $orderby;
  39. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top