尝试使用此自定义代码从前端创建帖子
从前端在自定义帖子中插入数据
if ( \'POST\' == $_SERVER[\'REQUEST_METHOD\'] && !empty( $_POST[\'action\'] ) && $_POST[\'action\'] == "product") {
$title = $_POST[\'title\'];
$post_type = \'product\';
//the array of arguements to be inserted with wp_insert_post
$front_post = array(
\'post_title\' => $title,
\'post_status\' => \'publish\',
\'post_type\' => $post_type
);
//insert the the post into database by passing $new_post to wp_insert_post
//store our post ID in a variable $pid
$post_id = wp_insert_post($front_post);
//we now use $pid (post id) to help add out post meta data
update_post_meta($post_id, "short_description", @$_POST["short_description"]);
update_post_meta($post_id, "price", @$_POST["price"]);
update_post_meta($post_id, "length", @$_POST["length"]);
此处为HTML代码
<form method="POST">
<label>Product Name</label>
<input type="text" value="" class="input-xlarge" name=\'title\'>
<label>Product Description</label>
<textarea value="" rows="3" class="input-xlarge" name=\'short_description\'>
</textarea>
<label>Price</label>
<input type="text" value="" class="input-xlarge" name=\'price\'>
<label>Dimensions (in):</label>
<input type="text" value="" class="input-xlarge" name=\'length\' placeholder="Length">
<div>
<button class="btn btn-primary">Add Product</button>
</div>
<input type="hidden" name="action" value="product" />
</from>