为了账号安全,请及时绑定邮箱和手机立即绑定

Wordpress - post_category 没有显示结果

Wordpress - post_category 没有显示结果

PHP
慕的地8271018 2021-06-30 15:00:13
我正在尝试对我的页面的最新帖子创建一个小概述。一切都适用于“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;                        ?>
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 279 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信