I’m using WP_Query arguments to output the results orderby title. But, if none of relationship were selected, it outputs all posts. How can I solve this?
<?php
$ids = get_field('courses_offered', false, false);
$posts = get_field('courses_offered');
$the_query = new WP_Query(array(
'post__in' => $ids,
'post_type' => 'courses',
'posts_per_page' => -1,
'post_status' => 'any',
'orderby' => 'title',
'order' => 'ASC',
));
if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post();
?>