WP_Query 查询分类法的所有术语
我试图遍历特定分类中的所有帖子,无论它们所在的术语是什么(即遍历该分类中的所有术语)。
我有这样的代码:
<?php
$terms = get_terms('business-books');
$booksArgs = array(
'posts_per_page' => '1',
'tax_query' => array(array(
'taxonomy' => 'business-books',
'field' => 'slug',
'terms' => $terms
))
); $books = new WP_Query($booksArgs); while ($books->have_posts()) : $books->the_post(); $thumbnail = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), full ); ?>
<a href="<?php the_permalink(); ?>"><img src="<? echo get_bloginfo('template_directory'); ?>/timthumb.php?src=<? echo $thumbnail[0] ?>&w=110&h=155&zc=1" alt="<? get_the_title() ?>" /></a>
<h6><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h6>
<?php endwhile; ?>
我需要 $terms
返回“商业书籍”中所有术语的数组。
有人可以帮我处理这个数组吗?
谢谢你!
I'm trying to loop through all posts within a specific taxonomy, regardless of what term they're in (ie, through all terms in that taxonomy).
I have this code:
<?php
$terms = get_terms('business-books');
$booksArgs = array(
'posts_per_page' => '1',
'tax_query' => array(array(
'taxonomy' => 'business-books',
'field' => 'slug',
'terms' => $terms
))
); $books = new WP_Query($booksArgs); while ($books->have_posts()) : $books->the_post(); $thumbnail = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), full ); ?>
<a href="<?php the_permalink(); ?>"><img src="<? echo get_bloginfo('template_directory'); ?>/timthumb.php?src=<? echo $thumbnail[0] ?>&w=110&h=155&zc=1" alt="<? get_the_title() ?>" /></a>
<h6><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h6>
<?php endwhile; ?>
I need $terms
to return an array of all the terms in 'business-books'.
Can someone aid me with this array?
Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题是
$terms = get_terms('business-books');
需要是
$terms = get_terms('business-books', 'fields=names');
Problem was that
$terms = get_terms('business-books');
needs to be
$terms = get_terms('business-books', 'fields=names');