I would like to create a custom post when my form is submitted and insert form data into that custom post.

When I searched I found a suggestion to use "Gravity forms and gravity forms+custom post type". But I need my own solution.

This is my code:

$title= $_POST['your_name'];
$my_post = array(
  'post_title'    => wp_strip_all_tags( $title ),
  'post_content'  => $decription,
  'post_status'   => 'publish',
  'post type'     => 'EmpResume'
  //'post_author'   => 1,
  //'post_category' => array( 8,39 )

// Insert the post into the database
wp_insert_post( $my_post );

But it stored my form data in "wp_posts" table rather in my custom post.

  • 2
    IMHO, go with the plugin solution. If you do not know how to do this without a plugin, it is better to use a plugin or pay a developer to code it for you. This is just too big project to handle here, and most probably no one is going to code this for free – Pieter Goosen Jun 14 '16 at 10:57
  • I tried to install gravity form plugin but I could not install it. If u know any other plugin which will do this pls inform – shane Jun 14 '16 at 12:02
  • @TheDeadMedic can you tell me clearly what to do ? I have created custom fields using ACF only. – shane Jun 15 '16 at 5:08
  • Custom post types are always stored in the posts table. What exactly is your problem? – fuxia Jun 15 '16 at 7:42

Which plugin you're using for the contact form? It looks likeyou're thinking about Gravity forms. You can create it with a custom function when the action gform_after_submission is fired - https://www.gravityhelp.com/documentation/article/gform_after_submission/

For Contact form 7, there is another hook, see here: wpcf7_before_send_mail, wpcf7_mail_sent http://hookr.io/plugins/contact-form-7/4.3/

Ninjaforms...http://hookr.io/plugins/ninja-forms/2.9.28/#index=a for the other plugins you should have a look yourself.

If it's too complicated, go for plugin solution. I have found this one for Gravity forms but haven't tried it personally. https://wordpress.org/plugins/gravity-forms-custom-post-types/

  • "gform_after_submission" this function can be used only if you have its plugin right? But i cannot use as i do not have it. i tried but i cannot download the "gravity form" plugin. any link to download will be helpful – shane Jun 15 '16 at 5:09
  • Ah, sorry, that's missundersunding from my site. You have to buy a licence. However, this kind of action/hook is supported in many other contact forms, which are free. I have updated the answer. – kybernaut.cz Jun 15 '16 at 14:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.