如何使用wp_insert_post插入新的文章?

wp_insert_post() 函式用於插入新的文章。你需要傳遞一個關聯陣列,包含文章的各項引數,如標題、內容、分類等。例如:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
$post_data = array(
'post_title' => '新的文章',
'post_content' => '這是一篇新的文章。',
'post_status' => 'publish', // 設定為 'publish' 以立即釋出文章
'post_type' => 'post', // 也可以設定為 'page' 或其他自定義的文章型別
);
$post_id = wp_insert_post($post_data);
$post_data = array( 'post_title' => '新的文章', 'post_content' => '這是一篇新的文章。', 'post_status' => 'publish', // 設定為 'publish' 以立即釋出文章 'post_type' => 'post', // 也可以設定為 'page' 或其他自定義的文章型別 ); $post_id = wp_insert_post($post_data);
$post_data = array(  
    'post_title' => '新的文章',  
    'post_content' => '這是一篇新的文章。',  
    'post_status' => 'publish', // 設定為 'publish' 以立即釋出文章  
    'post_type' => 'post', // 也可以設定為 'page' 或其他自定義的文章型別  
);  
$post_id = wp_insert_post($post_data);

如果你想要插入更復雜的文章,例如包含多個分類或標籤,你可以在 $post_data 陣列中新增更多的鍵值對。

未能解決您的問題?

請提交 聯絡工單