• Resolved andreadrago

    (@andreadrago)


    Hi Aurovrata,
    I really like your plugin, but I was wondering if it has a built-in functionality to edit an axisting post that was previously submitted, for example by passing an ID along with the form.
    If this is not possible, I already have a workaround, but in this situation i would need to avoid the creation of a new post from within a filter (i will map an hidden ID field, then check its value using a filter and do the update by myself). Is there a way to stop the creation?

    Thank you very much in advance!

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Aurovrata Venet

    (@aurovrata)

    I was wondering if it has a built-in functionality to edit an axisting post that was previously submitted,

    yes, this is possible. You have to know a few things first,

    – A mapped post that has been saved as a draft is reloaded automatically for the same author/logged in user.
    – A submitted post, as opposed to a saved/draft one, has a its meta-field _cf7_2_post_form_submitted set to ‘yes’, and this controls wheather or not an authors’ post is to be reloaded when the form is being displayed for the current user.

    However, you can override all this by actually hooking into the post loading process prior to displaying the form. The process used get_posts to retrieve a post, and takes the first post it finds.

    add_filter('cf7_2_post_filter_user_draft_form_query', 'custom_post_query',10,2);
    function custom_post_query($query_args, $post_type){
      if('my-mapped-post' === $post_type){ //check for your mapped post type.
        //set up your custom $query_args 
      }
      return $query_args;
    }
    Thread Starter andreadrago

    (@andreadrago)

    Hi Arovrata,
    thank you very much for the prompt response.
    I’ll go with the filter, but I have some things that may cause some problems:
    Since the filter is shared by all forms throughout the website, and I have two different forms that are associated with the same Custom Post Type, is there a way to get the form id within that filter? That way I could choose when to load a post or not. If in some situation I don’t want a post to be loaded, what should I return from the function?

    Thank you again for your support

    Plugin Author Aurovrata Venet

    (@aurovrata)

    is there a way to get the form id within that filter

    Indeed, with v2 unique form keys were introduced to make forms more portable between different WP installations, but some of these older hooks were not updated.

    I just released v3.8.1, with the key parameter added to the filter. See FAQ #23 for details.

    Thread Starter andreadrago

    (@andreadrago)

    Thank you very much, this is exactly what I needed ??

    Have a good day!

    Plugin Author Aurovrata Venet

    (@aurovrata)

    your’re wc, do leave a review!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Edit previously submitted posts’ is closed to new replies.