因此,我试图在与用户相关的分类法中获取术语列表。在每个术语内(想想子列表),应该是该术语的用户列表。这是我一直在使用的代码。但对于查询和非对象问题,它会返回几个错误。帮助
<?php $disciplines = get_terms(\'disciplines\');
foreach($disciplines as $discipline) {
echo \'<li><a href="#">\' . $discipline->name . \'</a></li>\';
$post_args = array( \'post_type\' => \'users\', \'disciplines\' => $discipline->term_id);
$posts = get_posts( $post_args );
foreach( $posts as $post ){
echo \'post title: \' . $post->post_title . \'<br />\';
}
}
?>
最合适的回答,由SO网友:Dan Bough 整理而成
get_terms 和get_posts 返回数组而不是对象。
尝试以下操作:
<?php $disciplines = get_terms(\'disciplines\');
foreach($disciplines as $discipline) {
echo \'<li><a href="#">\' . $discipline[\'name\'] . \'</a></li>\';
$post_args = array( \'post_type\' => \'users\', \'disciplines\' => $discipline[\'term_id\']);
$posts = get_posts( $post_args );
foreach( $posts as $post ){
echo \'post title: \' . $post[\'post_title\'] . \'<br />\';
}
}
?>