下面的函数按字母顺序返回,而不是按任意顺序返回
是否可以-不-按字母顺序返回,但按数组中给出的确切顺序返回?
add_filter(\'the_content\', \'my_function\');
function my_function($content) {
if ( is_single() && in_category( \'5\' ) ) {
the_post_thumbnail(\'thumbnail\', array(\'class\' => \'top-post-img\' ));
global $post;
$term_list=wp_get_post_terms($post->ID,array(\'school\',\'article\',\'teacher\'),array( "fields" => "names"));
?>
<div style="margin:45px;">
School: <strong><?php print_r($term_list[0]); ?></strong><br />
Article: <strong><?php print_r($term_list[1]); ?></strong><br />
Teacher: <strong><?php print_r($term_list[2]); ?></strong>
</div>
<?php
return $content;
} else {
return $content;
}
}
我尝试添加:array (\'orderby\' => \'post__in\'), array (\'post__in\' => \'24\', \'10\', \'3\', \'46\' )
数字是分类ID,但它不会更改任何内容,也不会引发错误。为了找到分类ID,我使用了以下代码,还是这是错误的代码?
$terms = get_the_terms( $post->ID , \'taxonomy-name\' );
if($terms) {
foreach( $terms as $term ) {
echo $term->term_id.\'<br />\';
}
}
我应该使用list_filter
在代码中的某个地方或下面的某个地方print_r
?已添加
var_dump($term_list);
看看输出是否会显示其他内容,但不是,它是相同的。。按字母顺序排列我肯定忘了一些,但忘了什么,忘了在哪里。还是我的方法完全错了
很想找到一个解决方案
提前感谢您花费的所有时间和精力。