Insert Custom Post Type data from the front-end by a user

We created a custom post type “items” and it is showing in the admin. Now, we want users to insert an item from the front-end. This will be linked to a menu item called “My Account” so a user can see all his inserted items and can add new item by clicking a link “Add New Item”.

How can we achieve this?

Related posts

3 comments

  1. I know the community prefers coded answers rather than a plug-in alternative. Especially since alot of frontend dedicated plug-ins are bloated or fail to accomplish most users desires.

    But I would recommend a combination of Gravity forms, which is well supported and documented, this will give you or your client easily manageable front facing forms which can submit to a custom post type and/or custom fields.

    Gravity sticky List – which will extend Gravity forms and allow front-end editing and/or display of already submitted forms/posts.

  2. Try This Custom Code For Create Post From Front End

    Insert Data in Custom Post From Front End

    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 Code Here

    <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>
    

Comments are closed.