Skip to content

Instantly share code, notes, and snippets.

@igmoweb
Last active November 26, 2015 17:41
Show Gist options
  • Save igmoweb/218d81f3d305646a55f2 to your computer and use it in GitHub Desktop.
Save igmoweb/218d81f3d305646a55f2 to your computer and use it in GitHub Desktop.
meta query
add_action( 'pre_get_posts', 'order_conciertos_by_date' );
function order_conciertos_by_date( $query ) {
if ( is_admin() )
return;
if ( $query->get( 'post_type' ) != 'concierto' )
return;
$today = current_time( 'timestamp' );
$today = date( 'Ymd', $today );
$meta_query = array(
array(
'key' => 'show_fecha',
'compare' => '>=',
'value' => $today,
'type' => 'numeric',
)
);
$query->set( 'meta_query', $meta_query );
$query->set( 'meta_key', 'show_fecha' );
$query->set( 'orderby', 'meta_value_num' );
$query->set( 'order', 'DESC' );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment