function get_issues() {
$output = array();
$hlterms = get_terms('issue', array('orderby' => 'id', 'order' => 'DESC','hide_empty' => false));
foreach($hlterms as $term){
array_push($output, $term->term_id);
}
return $output;
}
This would return you term id as per the recent and then in your second function start iterating to get the posts for latest issue.
function get_posts_for_current_issue() {
$total_issues = get_issues();
foreach($total_issues as $issue_id){
$args = array(
'post_type' => 'post',
'status' => 'publish',
'tax_query' => array(
array(
'taxonomy' => 'issue',
'field' => 'id',
'terms' => $issue_id
)
)
);//end of args
$current_issue_posts = get_posts($args);
if(!is_wp_error($current_issue_posts) && count($current_issue_posts)>0){
return $current_issue_posts; //will terminate the loop if posts found
}
}//end of foreach
}//end of function
You might need to turn on the WP_DEBUG, as I can’t test the code.