PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Overwrite Custom Post type using Form?

  1. graphical_force
    Member

    Hi, I have a form that users can use to become a Vendor. Submission of the form creates a custom post type and stores other fields of the form in custom fields. The issue I am having is that the user cannot edit their Vendor Custom Post Type. What I was wanting to know if it is possible for them to overwrite the custom post type if they submit a new form? Right now, it will just show two custom post types.

    Anyone have any suggestions?

    Thanks!

    Posted 11 years ago on Wednesday January 23, 2013 | Permalink
  2. How about this 3rd party plugin:
    http://www.p51labs.com/gravity-forms-update-post-plugin-v0-5-1-released/

    Editing an existing entry or post created by a form is not a feature of Gravity Forms.

    The Directory and Add-ons add-on might also help, although it would change the way your directory is displayed: http://wordpress.org/extend/plugins/gravity-forms-addons/

    Finally, there is probably a way to load the existing post into a form and allowing the user to change the values and submit again. It would create a new entry, but you could update the existing post rather than create a new post.

    Posted 11 years ago on Wednesday January 23, 2013 | Permalink
  3. graphical_force
    Member

    Thanks for the reply. How might I go about loading a post into a form?

    Thanks.

    Posted 11 years ago on Wednesday January 23, 2013 | Permalink
  4. Well, it's slightly complicated and I don't know of anyone who has posted a complete solution. In theory though, it would work like this:

    Create a form with all the fields of the post you want people to be able to update. This could be similar to the form you currently use to create the post. I would not use post fields since that will create a new post. I would use regular form fields of the relevant type (file upload for a post image, single line text for the post title, paragraph for the post body, etc.)

    Then, on the advanced tab of each field you want them to be able to edit, check the "Allow field to be populated dynamically" and give the field a unique parameter name.

    Then, you would need to write a function that uses the gform_pre_render filter to pull information from the custom post to populate those fields. http://www.gravityhelp.com/documentation/page/Gform_pre_render

    In the function, you would retrieve the information from the post you want to update, ( http://codex.wordpress.org/Function_Reference/get_post ) then populate the fields with that information. When the form is displayed, that information will be visible in the form, ready to be edited.

    On submission, you would have to use the gform_after_submission hook to update the existing post ( http://codex.wordpress.org/Function_Reference/wp_update_post ). http://www.gravityhelp.com/documentation/page/Gform_after_submission You would take all the information that was submitted and rewrite (update) the existing post.

    It's possible to do. You'd have to consider how to allow only certain users to update certain posts, and how to display the list of posts they can edit.

    Another way around it would be to allow the logged in user to just edit the post on the front end. This would just be a WordPress plugin function. Something like this http://wordpress.org/extend/plugins/front-end-editor/

    Good luck

    Posted 11 years ago on Thursday January 24, 2013 | Permalink