Wordpress - 检查将来是否有帖子发布

时间:2012-04-20 12:35:57

标签: wordpress wordpress-plugin

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

有没有人提供一些代码示例?

3 个答案:

答案 0 :(得分: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 
) 

Reference

答案 1 :(得分:1)

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

答案 2 :(得分:0)

请参阅WordPress codex:

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

post_status填写future