Issue with getting post_id from meta key


I am having an issue and hoping to get some help. I have a form that creates a post (let’s call it game using advanced post creation add-on) on form submission. I would like to obtain the meta value from the meta_key: gravityformsadvancedpostcreation_post_id using the entry id and assign the meta value to a custom merge tag {mytag}. But for some reason I am not having any luck. It keeps on returning empty value.

form: 100
input id where merge tag is placed: 50
merge tag: {mytag}

Here is my code:

add_action('gform_after_submission_100', 'custom_function', 10, 2);
function custom_function($entry, $form){
	error_log('custom function called.');
	$entry_id = $entry['id'];

	$meta_value = gform_get_meta($entry_id, 'gravityformsadvancedpostcreation_post_id');
	error_log(' test meta value: ' . print_r($meta_value));
	$post_id = '';

	if(!empty($meta_value)) {
		$unserialized_data = unserialize($meta_value);
		if($unserialized_data !== false){

			if(is_array($unserialized_data) && isset($unserialized_data[0]['post_id'])){

				$post_id = $unserialized_data[0]['post_id'];

			} else {
				error_log('unserialized data does not have the expected structure');
				error_log('unserialized data: ' . print_r($unserialized_data, true));
		} else {
			error_log('failed to unserialize meta value');
	} else {
		error_log ('meta value is empty.');

	error_log('Post ID: ' . $post_id);
		$post_permalink = get_permalink($post_id);

			$entry_value = rgar($entry, '50');

			$updated_value = str_replace('{mytag}', $post_permalink, $entry_value);

			error_log('Updated value: ' . $updated_value);
	} else {
		error_log('failed to extract post id from meta value');

The log in debug is as follows:

custom function called.
meta value is empty.
failed to extract post id from meta value

What am I doing wrong?

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