我在$ _REQUEST中獲取post_title,post_content和其他內容以及圖像文件。我想在wordpress數據庫中保存所有這些信息。我有我的頁面以附件爲單位編程添加Wordpress帖子
<?php
require_once("wp-config.php");
$user_ID; //getting it from my function
$post_title = $_REQUEST['post_title'];
$post_content = $_REQUEST['post_content'];
$post_cat_id = $_REQUEST['post_cat_id']; //category ID of the post
$filename = $_FILES['image']['name'];
//I got this all in a array
$postarr = array(
'post_status' => 'publish',
'post_type' => 'post',
'post_title' => $post_title,
'post_content' => $post_content,
'post_author' => $user_ID,
'post_category' => array($category)
);
$post_id = wp_insert_post($postarr);
?>
這將獲得數據庫中的所有東西作爲後,但我不知道如何添加附件及其後meta。
我該怎麼做?有誰能夠幫助我?我很困惑,花了幾天的時間來解決這個問題。
你應該包括WP-load.php而不是配置文件。 – 2013-05-21 06:58:27