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.