Can someone help me to find the error in this php code

function assign_parent_terms($post_id, $post) {
$temp_taxonomies = get_post_taxonomies($post);
foreach ($temp_taxonomies as $temp_tax) {

$terms = get_the_terms($post_id, $temp_tax );

if ( ! empty($terms)) {

foreach($terms as $term) {

// note, if wanting to auto-select parents in all categories, replace all “w2dc-location” with $temp_tax

while($term->parent != 0 && !has_term( $term->parent, ‘w2dc-location’, $post )) {

/*

echo ‘<script language=”javascript”>’;

echo ‘alert(“in here”)’;

echo ‘</script>’;

*/

// move upward until we get to 0 level terms

wp_set_post_terms($post_id, array($term->parent), ‘w2dc-location’, true);

$term = get_term($term->parent, ‘w2dc-location’);

wp_set_object_terms($post_id, $term->ID, ‘w2dc-location’, true);
}
}
}
}

}
add_action(‘save_post’, ‘assign_parent_terms’, 10, 2);

Read more here:: Can someone help me to find the error in this php code

Leave a Reply

Your email address will not be published. Required fields are marked *