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;
}
这将根据最新版本返回术语id,然后在第二个函数中开始迭代以获取最新版本的帖子。
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
您可能需要打开WP\\u调试,因为我无法测试代码。