Skip to content

Instantly share code, notes, and snippets.

@serguk89
Last active November 15, 2018 01:14
Show Gist options
  • Save serguk89/d0957061d3b4735e2cca502e0aa809d1 to your computer and use it in GitHub Desktop.
Save serguk89/d0957061d3b4735e2cca502e0aa809d1 to your computer and use it in GitHub Desktop.
automatically select parent terms
add_action('set_object_terms', 'auto_set_parent_terms', 9999, 6); // automatically select parent terms
function auto_set_parent_terms( $object_id, $terms, $tt_ids, $taxonomy, $append, $old_tt_ids ) {
foreach( $tt_ids as $tt_id ) {
if ($parenttags = get_ancestors($tt_id, $taxonomy))
{
wp_set_object_terms( $object_id, $parenttags, $taxonomy, true );
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment