Post Submission Add-on requires admin action to register custom fields

I have a form that when submitted will create a post with about 30+ mapped-out custom fields. When the post is created, the custom fields appear in the admin window, but when var_dump’d in a page, it returns “bool(false)” until I manually, as an admin, proceed and Publish or Update the post in question.

I am using a code to set the post status as “pending” or “published” depending on the user role. If the user who submits the post is not a trusted member, then I accept making a validation myself. But in the case of a trusted member, when he would publish the post, the post will appear without any custom fields until I manually publish or update the post. The posts are mostly built with custom fields so it is imperative that the custom fields get registered correctly when the form is submitted.

What could be made to go around this issue?

The APC add-on simply creates the posts using WP core functions for it. According to the description of the issue, I would bet the third-party handling those custom fields displaying (the theme or third-party plugin used for them) is requiring an additional action that is only triggered when you use the WP editor and not when the post is created programmatically or with a third-party tool.

The following hook runs after the APC add-on creates the post gform_advancedpostcreation_post_after_creation - Gravity Forms

You can try the following snippet that would fire one of the action hooks that WordPress uses after publishing a post to see if that helps:

add_action( 'gform_advancedpostcreation_post_after_creation', function ( $post_id, $feed, $entry, $form ) {
	GFCommon::log_debug( __METHOD__ . '(): Running after post creation...' );
	$post = get_post( $post_id );
	do_action( 'wp_insert_post', $post_id, $post, true );
},10,4 );

If that doesn’t help, I would recommend you to reach the author of the theme/plugin handling those custom fields.

1 Like

I am using ACF Custom Fields Pro, maybe there is a built-in function I am unaware of.

Sadly the code snippet did not resolve the issue.

Gravity Forms doesn’t has any built-in support for ACF. It saves values using plain text, and for most field types ACF uses a different format to store values. If you check the documentation page for the APC filter above you will find an example that deals with GF checkboxes data to ACF checkboxes format.

If you need help saving other field types, I would recommend you to reach ACF support for advice on how to save the field data in the format expected by ACF.

I’ve noticed that much and been working around so that all my fields exported as strings and work as such. ACF treating my data is not part of the issue, fortunately. It’s really just about getting it to be “registered” upon submitting the form.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.