Wordpress在前端显示自定义帖子类型表单

Wordpress在前端显示自定义帖子类型表单,wordpress,Wordpress,更新:好的,现在自定义发布数据正确发布。。添加了post_type=>“假期”以使此工作正常。。。但现在我在提交时收到了404错误。有什么想法吗 我试图在Wordpress中的任何页面/帖子中添加前端表单,但此表单没有触发或保存任何数据。提交后它不会显示感谢信息(但表单使用[假期]快捷码确实显示良好)。该帖子不会添加到仪表板中我的自定义帖子类型“休假”区域(工作正常)。我是否需要告诉它,我以某种方式插入了一个自定义的帖子类型“假期”?请问我在想念谁 // Add shortcode to fro

更新:好的,现在自定义发布数据正确发布。。添加了post_type=>“假期”以使此工作正常。。。但现在我在提交时收到了404错误。有什么想法吗

我试图在Wordpress中的任何页面/帖子中添加前端表单,但此表单没有触发或保存任何数据。提交后它不会显示感谢信息(但表单使用[假期]快捷码确实显示良好)。该帖子不会添加到仪表板中我的自定义帖子类型“休假”区域(工作正常)。我是否需要告诉它,我以某种方式插入了一个自定义的帖子类型“假期”?请问我在想念谁

// Add shortcode to front end for vacation input

add_shortcode( 'vacation', 'vacation_shortcode' );

function vacation_shortcode() {
if($_POST['vacation']=="submit" && !empty( $_POST['action'] )) {
echo "Thanks for submitting your vacation request!";
}
if (isset ($_POST['title'])) {
$title =  $_POST['title'];
 } else {
echo 'Please add a description of your request!';
    }
?><form method="post" name="vacation_form" action="" id="vacation_form" >
<input type="text" name="title" value="Title of vacation request" />
<input type="text" name="_simple_vacation_type" value="Reason for absence" />
<input type="hidden" name="vacation" value="submit" />
<input type="hidden" name="action" value="new_vacation" />
<input type="submit" value="Submit">
<?php wp_nonce_field( 'new_vacation' ); ?>
</form>
<?php 
}
function simple_vacation_add_post(){

if($_POST['vacation']=="submit" && !empty( $_POST['action'] )) {

$title     = $_POST['title'];
$vacation_type = $_POST['_simple_vacation_type'];  

//the array of arguments to be inserted with wp_insert_post

$new_post = array(
'post_title'    => $title,
'post_type'     =>'vacation',
'post_status'   => 'publish'          
);

//insert the the post into database by passing $new_post to wp_insert_post
$pid = wp_insert_post($new_post);

//we now use $pid (post id) to help add our post meta data
add_post_meta($pid, '_simple_vacation_type', $vacation_type, true);
}
}

add_action('init','simple_vacation_add_post');
//将短代码添加到前端以进行假期输入
添加_短代码(‘假期’、‘假期_短代码’);
函数u短码(){
如果($_POST['vacation']==“submit”&&!empty($_POST['action'])){
echo“感谢您提交度假申请!”;
}
如果(isset($_POST['title'])){
$title=$_POST['title'];
}否则{
echo“请添加您请求的说明!”;
}
?>
从前端在自定义Post中插入数据

这里是HTML代码


品名
产品说明
价格
尺寸(英寸):
添加产品
从前端在自定义Post中插入数据

这里是HTML代码


品名
产品说明
价格
尺寸(英寸):
添加产品
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"]);
<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>