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') ); ?>

Read more here: Front-end form submission not creating post


If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Related Wordpress search:

, , , ,

Wordpress related questions and answers: