2013-08-23 21 views
0

我的要求是:: 創建一個很少數量的帖子(比如說10個帖子)的備份類別,我只需要保存這個數量的最新帖子。如何在wordpress中以編程方式添加有限數量的帖子?

我用下面的代碼創建後:

$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

試試這個: 插入任何職位之前,請查看類別職位的數目。

$args = array(
    'include'     => '9', 
    'taxonomy'     => 'category', 
    'pad_counts'    => true 
); 
$categories = get_categories($args); 
if($category[0]->count < 10){ 
    // Your Code Goes Here 
} 
+0

謝謝。我會試試看。 – Akshay

相關問題