Custom Fields for Custom Post Type & Gravity Forms

Support MB Custom Table Custom Fields for Custom Post Type & Gravity FormsResolved

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #35993
    John RoodJohn Rood
    Participant

    I've got a Gravity Form that creates my custom post type after submission. I have a field group set up with custom fields that I'd like to populate based on values from the Gravity Form after submission and the new post is created.

    I've got the following code in place, however I'm not sure what else I need. Is there a way that I can simply map the fields from Gravity Forms over to the Meta Box custom fields so I don't have to do each individually in code?

    function update_meta_box_custom_fields( $post_id, $feed, $entry, $form ) {
    		
    		// Get value from form
    		$value = '';
    		foreach ( $form['fields'] as &$field ) {
    			if ( $field->id == 40 ) {
    				$value = $field->value;
    			}
    		}
    
    		$data = [
    			'text_07vqcymyr6iw' => $value,
    		];
    		
    		\MetaBox\CustomTable\API::add( $post_id, $table, $data );
    	}
    	// Gravity Form #4
    	add_action( 'gform_advancedpostcreation_post_after_creation_4', 'update_meta_box_custom_fields', 10, 4 );
    #36001
    John RoodJohn Rood
    Participant

    Taking another look at the Custom Fields section in Gravity Forms for the Advanced Post Creation it's possible to add a new custom field in and use the 'text_07vqcymyr6iw' field name from Meta Box Custom Field Group solves my issue. But I'm still left mapping each field from the form over, is there an easier way to do this or am I stuck doing this for each field?

    #36016
    Long NguyenLong Nguyen
    Moderator

    Hi John,

    I think you still need to map a specific field ID to GF form field value because we don't know which field ID will be assigned to what value. You can also follow this documentation to get all fields info https://docs.metabox.io/functions/rwmb-get-registry/

    #38079
    John RoodJohn Rood
    Participant

    This is what we ended up doing. Thanks! This can be closed.

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.