猿问

Wordpress - post_category 没有显示结果

我正在尝试对我的页面的最新帖子创建一个小概述。一切都适用于“wp_get_recent_posts”查询。现在我试图在标题中添加一些图标,但是只要我尝试获取帖子的post_category,它总是不显示任何结果。


如果试图将$args 'category' => 更改为 ' 1 , 2 , 3 , 4 ,...' 但它没有帮助。


任何建议都非常感谢。我的代码:


                    <?php


                        $args = array(

                            'numberposts' => 5,

                            'offset' => 0,

                            'category' => '',

                            'orderby' => 'post_date',

                            'order' => 'DESC',

                            'include' => '',

                            'exclude' => '',

                            'meta_key' => '',

                            'meta_value' =>'',

                            'post_type' => 'post',

                            'post_status' => 'draft, publish, future, pending, private',

                            'suppress_filters' => true

                        );


                        $recent_posts = wp_get_recent_posts( $args, ARRAY_A );


                        foreach($recent_posts as $post):

                            if($post['post_category'] == 1):

                                echo "<p><i class=\"fas fa-book\">&nbsp;&nbsp;</i>{$post['post_title']}<br></p>";

                            elseif($post['post_category'] == 2):

                                echo "<p><i class=\"fas fa-desktop\">&nbsp;&nbsp;</i>{$post['post_title']}<br></p>";

                            endif;

                            echo $post['post_category']; //Debug, no output.

                            echo $post['post_title']; //Debug, output: "example post"

                            echo $post['post_date']; //Debug, output: "2019-05-21"

                        endforeach;


                        ?>


慕的地8271018
浏览 280回答 1
1回答
随时随地看视频慕课网APP
我要回答