Skip to content

Instantly share code, notes, and snippets.

@dnavarrojr
Created July 30, 2018 13:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dnavarrojr/975f9227f2e40e9c978fe5538235b6d8 to your computer and use it in GitHub Desktop.
Save dnavarrojr/975f9227f2e40e9c978fe5538235b6d8 to your computer and use it in GitHub Desktop.
WordPress Sort CPT by Date and Time
$args = array(
'post_type' => 'eventsapi',
'numberposts' => -1,
'meta_query' => array(
'event_date' => array( 'key' => 'event_date', 'value' => $date, 'compare' => '=' ),
'event_time' => array(
'relation' => 'OR',
array( 'key' => 'event_start', 'compare' => 'EXISTS' ),
array( 'key' => 'event_start', 'compare' => 'NOT EXISTS' ),
),
),
'orderby' => 'event_date event_time',
'order' => 'ASC',
);
$eventsapi = get_posts( $args );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment