Skip Navigation

[Resolved] Sending a field created by CRED to another non Types field

This support ticket is created 7 years, 4 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 -
- 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

Tagged: 

This topic contains 1 reply, has 2 voices.

Last updated by Noman 7 years, 4 months ago.

Assisted by: Noman.

Author
Posts
#547281

I am trying to have a field created in a CRED form sent to another non Types field (part of the 'GEO my WP plugin) at the point the post is created. I have the following code provided by the plugin developer:

 /* 
This example can be used with any post type. 
The update location function is triggered using the 
save_post_{post-type-name} action which fires every time 
a new post is created or an existing post is updated.  
The action hook passes the argument $post_id into the update location function.
Assuming that the address entered in the front end form 
is saved via custom field we can easily pull it using get_post_meta function and 
pass it to the update location function. 
Otherwise, if the address is saved somewhere else ( ex custom table )
you will need to pull it directly from the database 
unless there is a function provided for that ( maybe when using a different plugin ).
The example below I will simply use the post type "post" 
and the custom field "address" as the address holder.
*/

//rename your custom function as you wish ( or leave it as is ).
function gmw_update_post_type_post_location(  $post_id ) {
	
    // Return if it's a post revision
    if ( false !== wp_is_post_revision( $post_id ) )
        return;

    // check autosave //
    if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
        return;
    }

    //check if user can edit post
    if ( !current_user_can( 'edit_post', $post_id ) )
        return;

    //get the address from the custom field "address"
	$address = get_post_meta( $post_id, 'wpcf-expert-post-code', true );

	//varify that address exists. Otherwise abort the function.
	if ( empty( $address ) )
		return;
   
	//include the update location file file
	include_once( GMW_PT_PATH .'/includes/gmw-pt-update-location.php' );
  	
    //make sure the file included and the function exists
	if ( !function_exists( 'gmw_pt_update_location' ) )
		return;
   
    //Create the array that will pass to the function
	$args = array(
			'post_id' => $post_id, //Post Id of the post 
        array( 
            'street' => $address,
			'apt' => $address,
			'city' => $address,
			'state' => $address,
			'zipcode' => $address, 
			'country' => $address
            )
	);

	//run the udpate location function
	gmw_pt_update_location( $args );
}
//execute the function whenever post type is being updated
add_action( 'save_post_expert', 'gmw_update_post_type_post_location' );

However it isnt working. 'wpcf-expert-post-code' is the name of the Types field I am trying to send to.

I would appreciate some help with this.

Regards,

David

#547304

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi David,

Thank you for contacting Toolset Support. Looks like you are not using the correct action, the hook that you will need to use is “cred_save_data”
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data

I hope this will resolve the issue. Thank you