1

我需要检查将来是否有要发布的帖子。我想使用 WP 功能,不能通过 mysql_query 直接访问数据库。

有人有一些代码示例吗?

4

3 回答 3

2
$count_posts = wp_count_posts();
$future_posts = $count_posts->future;
if($future_posts > 0)
{
    // future posts available
}

或者

if(wp_count_posts()->future > 0)
{
    // future posts available
}

wp_count_posts()返回

stdClass Object 
( 
    [Publish] => 60 
    [Future] => 1 // only one is available 
    [Draft] => 9 
    [Pending] => 3 
    [Private] => 0 
    [Trash] => 0 
    [Auto-draft] => 3 
    [Inherit] => 0 
) 

参考

于 2012-04-20T12:57:27.473 回答
1

$future_posts = get_posts('post_status' => 'future');

于 2012-04-20T12:42:41.303 回答
0

请参阅 WordPress 法典:

http://codex.wordpress.org/Template_Tags/get_posts

用于post_status填写future

于 2012-04-20T12:40:33.617 回答