I am trying to use the save_post hook, but it is not working as intended: I want to save the Taxonomy (Region) with the ID 75 when the radio button 'wpcf-proprty_online' is 'y'. When I open the Post & the 'wpcf-proprty_online' is first 'n' and then I change it to 'y' and hit save, it's not saving the region 75, only if I click a second time on save.
function save_online_shop($post_id) {
if(get_post_meta($post_id, '', true)) {
if(get_post_meta($post_id, 'wpcf-proprty_online', false)) {
if(get_post_meta($post_id, 'wpcf-proprty_online', true) == 'y')
{
wp_set_post_terms( $post_id, 75, 'region' );
}
}
}
}
add_action('save_post_listing', 'save_online_shop', 999999);
I don't really get why this is happening, I also played around with the priority but couldn't get it working. I am using the save_post hook a similar way like that on another occasion, and am having the same problem.