我的要求是:: 创建一个备份少数帖子(比如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);
答案 0 :(得分:0)
试试这个: 在插入任何帖子之前,请检查该类别中的帖子数量。
$args = array(
'include' => '9',
'taxonomy' => 'category',
'pad_counts' => true
);
$categories = get_categories( $args );
if($category[0]->count < 10){
// Your Code Goes Here
}