Advertisement
maxworkingwell

Sync two taxonomies from two CPTs in toolset relationship

May 20th, 2022
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.59 KB | None | 0 0
  1. // Manage  Taxonomies
  2. function tax_hadle_func($post_id, $post) {
  3.  
  4. $terms = wp_get_post_terms($post_id, 'product_cat', array("fields" => "all"));
  5. $boat_ids = toolset_get_related_posts($post_id, 'boat-product', 'child');
  6. $ids = array_map(function ($term) {
  7. return get_term_by('slug', $term->slug, 'boat-cat')->term_id;
  8. }, $terms);
  9. // print_r( $ids );
  10.  
  11. remove_action('save_post', 'tax_hadle_func',30,2);
  12. add_action('save_post', 'tax_hadle_func',30,2);
  13. foreach ($boat_ids as $boat_id) {
  14. wp_set_object_terms($boat_id, $ids, 'boat-cat', true );
  15. }
  16. }
  17. add_action('save_post', 'tax_hadle_func',30,2);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement