如何在wordpress中根据类别(分类法)检索帖子(书籍)? [英] How to retrieve posts(books) based on category(taxonomy) in wordpress?

查看:31
本文介绍了如何在wordpress中根据类别(分类法)检索帖子(书籍)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试显示特定类别(分类法)的帖子,即Book1".

I am trying to display posts of specific category(taxonomy) that is 'Book1'.

我尝试使用以下代码显示它.

I tried to display it with the following code.

                    $args = array(
                        'post_type' => 'book',
                        'posts_per_page' => 6,
                        'tax_query' => array(
                            array(
                                'taxonomy' => 'Book1',
                                'field' => 'id',
                                'terms' => 1
                            )
                        )
                    );
                    echo '<br>';
                    $postss = get_posts( $args );

                    if ( ! empty( $postss ) && is_array( $postss ) ) {
                        // Run a loop and print them all
                        $i=1;
                        foreach ( $postss as $termm ) { 
                                echo ' '.$i.' '.$termm->post_title. '<br>';
                                $i++;
                        }
                    }
               ?>

在输出中没有显示任何项目.

In output no any item is displayed.

推荐答案

我是这样做的.谢谢大家.

I did it by doing like this. Thanks all.

        $args = array(
            'post_type' => 'book',
            'cat' => '35'
        );
        echo '<br>';
        $postss = query_posts($args);
        if ( ! empty( $postss ) && is_array( $postss ) ) {
            // Run a loop and print them all
            ?><?php $i=1;
            foreach ( $postss as $termm ) { ?>

                    <?php echo ' '.$i.' '.$termm->post_title. '<br>';$i++;?>
                <?php
            }
        }

这篇关于如何在wordpress中根据类别(分类法)检索帖子(书籍)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆