WP_Query 查询分类法的所有术语

发布于 2024-11-17 03:37:43 字数 1043 浏览 3 评论 0原文

我试图遍历特定分类中的所有帖子,无论它们所在的术语是什么(即遍历该分类中的所有术语)。

我有这样的代码:

<?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] ?>&amp;w=110&amp;h=155&amp;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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冷月断魂刀 2024-11-24 03:37:43

问题是

$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');

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文