Skip to content

Instantly share code, notes, and snippets.

@younes-dro
Created November 6, 2020 02:49
Show Gist options
  • Save younes-dro/77b527d662cb809b574e01423667f457 to your computer and use it in GitHub Desktop.
Save younes-dro/77b527d662cb809b574e01423667f457 to your computer and use it in GitHub Desktop.
Exclude the top level parents Taxonomy
add_filter('terms_clauses', function ( $pieces, $taxonomies, $args ) {
if (!isset($args['wpse_exclude_top']) || 1 !== $args['wpse_exclude_top']
)
return $pieces;
$pieces['where'] .= ' AND tt.parent > 0';
return $pieces;
}, 10, 3);
$terms = get_terms('category_aliment', ['wpse_exclude_top' => 1]);
if ($terms && !is_wp_error($terms)
) {
echo '<ul>';
foreach ($terms as $term) {
echo '<li><a href="' . get_term_link($term) . '">' . $term->name . '</a></li>';
}
echo '</ul>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment