skip to Main Content

I’m using webhooks as documented here: https://docs.gravityforms.com/calendar-events-webhooks-addon-wp-restapi/ to add a new event to the Modern Tribe Events Calendar using Gravity Forms.

I have a radio field for the Venues which is auto populated using the Gravity Wiz ‘Populate Anything’ add on which works really well and saves to the newly created event but I want to add the option to add a new venue in the form too (and for this to be saved as a Venue Post and also be related to the newly created event).

I have access to another add on from Gravity Wiz called Nested Forms, which I can use to create the new Venue (also using the Advanced Post Creation add on from Gravity Forms) but I can’t work out the function I need to write to get this saved alongside the newly created Event.

3

Answers


  1. Chosen as BEST ANSWER

    function pre_submission_handler( $form ) { $venueId = rgpost( 'input_25' );

    $created_posts = gform_get_meta( $venueId, 'gravityformsadvancedpostcreation_post_id' );
    
    if (!empty($created_posts)) {
    
        foreach ( $created_posts as $post ) {
            $post_id = $post['post_id'];
        }
    
        $_POST['input_24'] = $post_id;
    }
    

    }

    Solved by mapping one field to another in the end.


  2. You may just need to add the following to your functions.php to run the API for your nested form:

    add_filter( ‘gpnf_enable_feed_processing_setting’, ‘__return_true’ );

    See more info here:
    https://gravitywiz.com/documentation/gravity-forms-nested-forms/#feed-processing

    Login or Signup to reply.
  3. This should work:

    //after submission
    add_action( 'gform_after_submission_453', 'update_venue', 10, 2 );//replace 453 with gravity form id
    function update_venue($entry, $form ){
       if($entry['1.1'] !== 'Yes'){//replace 1.1 with the field number of the "create new venue?" question. Replace Yes with whatever your checkbox value is
          return;
       }else{
          // Create post object
          $venue_post = array(
            'post_title'    => wp_strip_all_tags( $entry['4'] ),//replace 4 with field id of venue name
            'post_content'  => $entry['5'],//replace 5 with field id with venue description
            'post_status'   => 'publish',
            'post_author'   => 1,
            'post_category' => array( 25,68 ) //replace 25 and 68 with category ids if there are any
          );
           
          $venue_ID = wp_insert_post( $venue_post );
          $entry['3'] = $venue_ID;//replace 3 with number of the dropdown venue field
          $result = GFAPI::update_entry( $entry );
       }
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search