Sign up ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm trying to use a front end form to create a post. I've been trying for a while now but I the post is not created. I'm using the code below, i'm not sure if i've forgot something.

<?php Starkers_Utilities::get_template_parts( array( 'parts/shared/html-header','parts/shared/header') ); ?>

function ty_front_end_form() {



function ty_save_post_data() {

    if ( empty($_POST) || !wp_verify_nonce($_POST['name_of_nonce_field'],'name_of_my_action') )
       print 'Sorry, your nonce did not verify.';


        // Do some minor form validation to make sure there is content
        if (isset ($_POST['title'])) {
            $title =  $_POST['title'];
        } else {
            echo 'Please enter a title';
        if (isset ($_POST['description'])) {
            $description = $_POST['description'];
        } else {
            echo 'Please enter the content';

        $tags = $_POST['post_tags'];
        $tags = "";

        // Add the content of the form to $post as an array
        $post = array(
            'post_title' => wp_strip_all_tags( $title ),
            'post_content' => $description,
            'post_category' => $_POST['cat'],  
            'tags_input' => $tags,
            'post_status' => 'publish',         
            'post_type' => $_POST['post-type'] 

        $location = home_url(); 

        echo "<meta http-equiv='refresh' content='0;url=$location' />"; exit;
    } // end IF


<div class="form-wrap" style="margin-top: 300px;">

<form id="custom-post-type" name="custom-post-type" method="post" action="">

    <p><label for="title">Post Title</label><br />

    <input type="text" id="title" value="" tabindex="1" size="20" name="title" />

    <p align="right"><input type="submit" value="Publish" tabindex="6" id="submit" name="submit" /></p>

    <?php wp_nonce_field( 'name_of_my_action','name_of_nonce_field' ); ?>



<?php Starkers_Utilities::get_template_parts( array( 'parts/shared/footer','parts/shared/html-footer') ); ?>
share|improve this question
It seems some fields don't have corresponding inputs, like the post type. Is there an input for the post type? –  engelen Jun 24 '14 at 9:56
Post type is should always be set as Post –  Steven_Harris_ Jun 24 '14 at 10:18
So why do you use $_POST['post-type'] instead of post (or omitting post_type altogether, as it's post by default)? –  engelen Jun 24 '14 at 10:28

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.