Show recent published posts

时间:2015-01-29 作者:Sadik

我想列出最近published 我的wp博客的帖子,并排除某些类别的帖子。以下代码运行良好,列出了10篇最近发表的文章,忽略了列出类别中的文章。然而,草案员额也被列出。

$args = array( \'numberposts\' => \'10\', \'tax_query\' =>
 array(
     \'post_type\' => \'post\',
     \'post_status\' => array( \'publish\' ),
     \'tax_query\' => array(
         \'relation\' => \'AND\',
         array(
             \'taxonomy\' => \'category\',
             \'field\' => \'id\',
             \'terms\' => array( 10, 11, 57 ),
             \'operator\' => \'NOT IN\',
         ),
     ),
 )
);



$recent_posts = wp_get_recent_posts(  $args );
foreach( $recent_posts as $recent ){
    echo \'<li><a href="\' . get_permalink($recent["ID"]) . \'">\'.   $recent["post_title"].\'</a> </li> \';
    }
?>
具有的行\'post_status\' => array( \'publish\' ),\'post_status\' => \'publish\', 不起作用。有什么线索吗?

1 个回复
最合适的回答,由SO网友:cybmeta 整理而成

你使用的论点是错误的。它们应该是:

$args = array(
            \'numberposts\' => \'10\',
            \'post_type\'   => \'post\',
            \'post_status\' =>\'publish\',
            \'tax_query\'   => array(
                \'taxonomy\' => \'category\',
                \'field\' => \'id\',
                \'terms\' => array( 10, 11, 57 ),
                \'operator\' => \'NOT IN\',
            )
 );
或更短:

$args = array(
            \'numberposts\'        => \'10\',
            \'post_type\'          => \'post\',
            \'post_status\'        => \'publish\',
            \'category__not_in\'   => array( 10, 11, 57 )
 );

结束

相关推荐

PUBLISH_POST挂钩不适用于计划的帖子

我对wp在推特上发布一条推特,链接到我通过电子邮件发送到wordpress的一篇设置为“待定”的帖子有点不太满意。组织网站。电子邮件中有一个页脚,其中包括我的手机号码。我决定创建自己的插件。add_action(\'publish_post\', \'tcr_tweet\'); /* the function */ function tcr_tweet($postID) { if( ( $_POST[\'post_status\'] == \'p