2

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.

0

Did you try removing the IF statements and use save_post hook instead of save_post_listing to see if an IF statement is blocking the wp_set_post_terms?

Also try wp_set_object_terms instead of wp_set_post_terms.

Furthermore, if you can make sure it has to do with the if(get_post_meta($post_id, 'wpcf-proprty_online', true) == 'y') statement, then this post_meta has not been updated before you are execusting this function. So why not update it within this function to make sure the value == 'n' or 'y'.

update_post_meta( $post_id, 'wpcf-proprty_online', $_POST['the_name_of_yr_field'] );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.