Tell us what you are trying to do?
I have a Gravity Form that uses the Advanced Post Creation addon to create 2 posts of different types on submission. First, it creates a Theme (theme-post) post type post, and then it creates a Practice Criteria (practice-criteria) post type post.
I have a one-to-many relationship between the two post types (slug is theme-practice-criteria-relationship).
I am using a Gravity Forms hook for when the advanced post creation is done for both posts to create a toolset relationship between the two posts.
Here is the code I am using:
add_filter( 'gform_advancedpostcreation_post_after_creation_1', 'apc_toolset_setparent', 10, 4 );
$post_id_of_theme = '';
function apc_toolset_setparent( $post_id, $feed, $entry, $form ) {
GFCommon::log_debug( 'Feed ID => ' . $feed['id'] );
if ($feed['id'] == 5) {
$GLOBALS['post_id_of_theme'] = $post_id;
GFCommon::log_debug( 'Post ID of Theme (Feed 5) => ' . $GLOBALS['post_id_of_theme'] );
}
if ($feed['id'] == 1) {
GFCommon::log_debug( 'Field Type => ' . rgar( $entry, '27' ) );
if (rgar( $entry, '27' ) == "1") {
$theme_id = intval(rgar ($entry, '28'));
$theme_post = get_post($theme_id);
$criteria_post = get_post($post_id);
GFCommon::log_debug( 'Theme Post ID in Field 28 => ' . $theme_id);
GFCommon::log_debug('Criteria Post ID => '. $post_id);
toolset_connect_posts('theme-practice-criteria-relationship', $theme_id, $post_id );
// toolset_connect_posts('theme-practice-criteria-relationship', $theme_post, $criteria_post );
GFCommon::log_debug('Post connection code has run');
}
else {
$theme_id = intval($GLOBALS['post_id_of_theme']);
$theme_post = get_post($theme_id);
$criteria_post = get_post($post_id);
GFCommon::log_debug( 'Post ID of Theme (Global) => ' . $GLOBALS['post_id_of_theme'] );
GFCommon::log_debug( 'Post ID of Theme (Local) => ' . $theme_id );
GFCommon::log_debug( 'Post ID of Practice Criteria => ' . $post_id );
toolset_connect_posts('theme-practice-criteria-relationship', $theme_post, $criteria_post );
}
}
}
I don't see any errors, but the Gravity Forms log shows the correct theme_id and post_id but hangs at the toolset_connect_posts() function (none of the code after that executes.
I even ran a simple version where I just use the following code:
add_filter( 'gform_advancedpostcreation_post_after_creation_1', 'apc_toolset_setparent', 10, 4 );
function apc_toolset_setparent( $post_id, $feed, $entry, $form ) {
toolset_connect_posts('theme-practice-criteria-relationship', 166, $post_id );
}
Even this doesn't work.
My site is on PHP 7.4, hosted with WPEngine.
All code has been added to Toolset's Custom Code section and is active.