
Pass custom field to GeomyWP field when post is saved
- or -
Post a project like this3073
$$
- Posted:
- Proposals: 3
- Remote
- #1653683
- Awarded
Description
Experience Level: Intermediate
Hi there,
I have created a custom field. A post is created by a user on the frontend and as part of that a custom field is created that contains a post code. I need to pass that field to a plugin called GeomyWP at the point the custom post is created. There are instructions here on how to do this:
http://docs.geomywp.com/gmw_pt_update_location/
However I have not been able to get them to work.
Currently my code 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
'address' => $address
);
//run the udpate location function
gmw_pt_update_location( $args );
}
//execute the function whenever post type is being updated
add_action( 'save_post_experts', 'gmw_update_post_type_post_location' );
wpcf-expert-post code is the custom field created by the user and the custom post type is 'expert'
Do you think you could help with this?
Regards,
David Robinson
I have created a custom field. A post is created by a user on the frontend and as part of that a custom field is created that contains a post code. I need to pass that field to a plugin called GeomyWP at the point the custom post is created. There are instructions here on how to do this:
http://docs.geomywp.com/gmw_pt_update_location/
However I have not been able to get them to work.
Currently my code 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
'address' => $address
);
//run the udpate location function
gmw_pt_update_location( $args );
}
//execute the function whenever post type is being updated
add_action( 'save_post_experts', 'gmw_update_post_type_post_location' );
wpcf-expert-post code is the custom field created by the user and the custom post type is 'expert'
Do you think you could help with this?
Regards,
David Robinson
David R.
100% (8)Projects Completed
8
Freelancers worked with
8
Projects awarded
33%
Last project
13 May 2021
United Kingdom
New Proposal
Login to your account and send a proposal now to get this project.
Log inClarification Board Ask a Question
-

Hi David,
Were you able to find a solution, or do you still need help in this?
HarshDavid R.25 Jul 2017Hi Harsh,
I have someone looking at it at the moment.
Regards,
David
468429
We collect cookies to enable the proper functioning and security of our website, and to enhance your experience. By clicking on 'Accept All Cookies', you consent to the use of these cookies. You can change your 'Cookies Settings' at any time. For more information, please read ourCookie Policy
Cookie Settings
Accept All Cookies