[英]How to add limited number of posts programmatically in wordpress?
我的要求是::创建一个用于备份少量帖子(例如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);
尝试以下操作:在插入任何帖子之前,检查类别中的帖子数量。
$args = array(
'include' => '9',
'taxonomy' => 'category',
'pad_counts' => true
);
$categories = get_categories( $args );
if($category[0]->count < 10){
// Your Code Goes Here
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.