I have created a CPT based on classes where you can select Group or Online.
I have then created an ACF where the user can select to show All, Online or Group.
When Group or Online are selected the query shows ok and in the right date order. However, when All is selected it shows the all but date order is out.
if ( get_sub_field( 'class_type' ) == 'All' ):
$metaquery = array(
'relation' => 'AND',
'meta_key' => 'date',
'orderby' => 'meta_value',
'order' => 'ASC'
);
else:
$class_type = get_sub_field('class_type');
$metaquery = array(
'relation' => 'AND',
array(
'key' => 'class_type',
'value' => $class_type
),
array(
'key' => 'date',
'orderby' => 'meta_value',
'order' => 'ASC'
)
);
endif;
$number_of_classes = get_sub_field('number_to_show');
$args = array(
'post_type' => 'classes',
'posts_per_page' => $number_of_classes,
'meta_query' => $metaquery
);
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
$date = get_field('date');
$date_ouput = date("d M", strtotime($date));