0

我的要求是 :: 创建一个类别以备份少量帖子(比如 10 个帖子),我只需要保存该数量的最新帖子。

我使用以下代码创建帖子:

$new_post = array(
    'post_title' => $content,
    'post_status' => 'publish',
    'post_date' => $tweet_time,
    'post_author' => 1,
    'post_type' => 'post',
    'post_category' => array(9)
    );
$postid=wp_insert_post($new_post);
4

1 回答 1

0

试试这个:在插入任何帖子之前检查类别中的帖子数量。

$args = array(
    'include'                  => '9',
    'taxonomy'                 => 'category',
    'pad_counts'               => true 
);
$categories = get_categories( $args );
if($category[0]->count < 10){
    // Your Code Goes Here
}
于 2013-08-23T07:26:11.150 回答