我不知道你到底想要什么\'term_single\'
格式,但如果不完全符合您的要求,您可以根据需要修改以下内容。
我还建议不要用这个名字$posts
对于您的阵列,因为我相信WP有一个同名的全局,所以它可能会导致不受欢迎的有趣性。
最后,当您处于循环中时,您可以使用简单的函数来获取所需的所有信息(ID、名称等)-check out the Codex.
$query = new WP_Query($criterias);
if($query->have_posts()) : while ($query->have_posts()) : $query->the_post();
/** Get all terms (as objects) from the \'idm_real_tax\' taxonomy that are associated with this Post */
$terms = get_the_terms(get_the_ID(), \'idm_real_tax\');
/** Check that \'$terms\' is not empty */
if($terms && !is_wp_error($terms)) : // It\'s not...
$term_names = array(); // Pre-stage to avoid errors
/** Loop through each term object and add just the name to the \'$term_names\' array */
foreach($terms as $term) :
$term_names[] = $term->name;
endif
/** Join all of the term names together to make a comman seperated string of term names */
$term_names_string = (!empty($term_names)) ? join(", ", $term_names) : \'\';
endif;
$my_posts[] = array(
\'id\' => get_the_ID(),
\'permalink\' => get_permalink(),
\'title\' => get_the_title(),
\'excerpt\' => get_the_excerpt(),
\'thumbnail\' => get_the_post_thumbnail(get_the_ID(), \'carrousel-realisation\'),
\'pager_thumbnail\' => get_the_post_thumbnail(get_the_ID(), \'thumbnail\', array(\'class\' => \'img-thumbnail img-responsive\')),
\'term_single\' => $term_names
);
endwhile;
endif;