Advertisement
maxworkingwell

Match child post taxonomy to parent

May 20th, 2022
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.50 KB | None | 0 0
  1. // Manage  Taxonomies
  2. function tax_hadle_func($post_id, $post) {
  3.    
  4. $boat_ids = toolset_get_related_posts($post_id, 'boat-product', 'child');
  5. $child_terms = get_the_terms( $post_id, 'boat-cat' );
  6. $child_term_ids = wp_list_pluck( $child_terms, 'term_id' );
  7. remove_action('save_post', 'tax_hadle_func',30,2);
  8. add_action('save_post', 'tax_hadle_func',30,2);
  9. foreach ($boat_ids as $boat_id) {
  10. wp_set_post_terms( $boat_id, $child_term_ids, 'boat-cat', true );
  11. }
  12. }
  13. add_action('save_post', 'tax_hadle_func',30,2);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement