Skip Navigation

[Resolved] Copy post taxonomy value to another taxonomy on cred save

This support ticket is created 6 years, 3 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
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 16 replies, has 2 voices.

Last updated by jonB-5 6 years, 3 months ago.

Assisted by: Nigel.

Author
Posts
#1094821

Hi Nigel,

I have updated the plugins but am now dealing with a more pressing issue as a result (see thread at https://toolset.com/forums/topic/cred-login-page-display-issue-after-upgrade-to-latest-plugins/)

I will update you as soon as I have been able to properly test the 500 error issue.

#1098533

Hi Nigel,

Now the other issues are resolved have been able to properly test the code and can confirm it works correctly.

For reference...

The CRON Job Code to bring existing posts up to date: https://toolset.com/forums/topic/copy-post-taxonomy-value-to-another-taxonomy-on-cred-save/#post-1090231

The CRED Form Code to perform the same action for all new posts...

// Manage Voyage Country Taxonomies
add_action('cred_save_data', 'cred_save_voyage_countries', 10, 2);
function cred_save_voyage_countries($post_id, $form_data) {
   
   $forms = [ 90, 110 ];
   
   if ( in_array( $form_data['id'], $forms ) )
        {
   
        error_log("starting...");
  
        $embarkationcountry = wp_get_post_terms($post_id, 'embarkation-country');
        $disembarkationcountry = wp_get_post_terms($post_id, 'disembarkation-country');
  
        error_log(print_r($embarkationcountry, true)); //should be array of term objects
        error_log(print_r($disembarkationcountry, true)); //should be array of term objects
       
        if ( !empty( $embarkationcountry ) ){
       
            $emb_term_list = wp_get_post_terms($post_id, 'embarkation-country', array("fields" => "all"));
            $emb_term_slug = $emb_term_list[0]->slug;
       
            $country_slug_emb = get_term_by('slug', $emb_term_slug, 'countries');
            $country_id_emb = $country_slug_emb->term_id;
  
            error_log(print_r($emb_term_list, true));
            error_log(print_r($emb_term_slug, true));
            error_log(print_r($country_slug_emb, true));
            error_log(print_r($country_id_emb, true));
       
        }
        if ( !empty( $disembarkationcountry ) ){
       
            $dis_term_list = wp_get_post_terms($post_id, 'disembarkation-country', array("fields" => "all"));
            $dis_term_slug = $dis_term_list[0]->slug;
       
            $country_slug_dis = get_term_by('slug', $dis_term_slug, 'countries');
            $country_id_dis = $country_slug_dis->term_id; 
 
        error_log(print_r($dis_term_list, true));
            error_log(print_r($dis_term_slug, true));
            error_log(print_r($country_slug_dis, true));
            error_log(print_r($country_id_dis, true));             
       
        }
 
    error_log(print_r($country_id_emb, true));
    error_log(print_r($country_id_dis, true));
 
    $termsarray = array( $country_id_emb, $country_id_dis );
 
    error_log(print_r($termsarray, true));
 
    wp_set_post_terms($post_id, $termsarray, 'countries');
 
    }
}