Reputation: 3226
I'm not sure why this isn't working. I want to exclude categories 406, 982, and 1319 and their children from the list. I don't see any other arguments on wp codex. Does 'exclude' automatically exclude children? Is there another way to do this?
**Edit: I can't even limit the results to 10.
<?php
$args = array(
'exclude' => '406,982,1319',
'#' => '10'
);
$sidebar_artists = get_categories($args);
echo "<ul>";
foreach ($sidebar_artists as $sidebar_artist) {
echo '<li class="cat-item">' . $sidebar_artist->category_nicename . '</li>';
}
echo "</ul>";
?>
Upvotes: 2
Views: 3374
Reputation: 7451
Set parent to 0:
<?php
$args = array(
'orderby' => 'name',
'parent' => 0
);
$categories = get_categories( $args );
foreach ( $categories as $category ) {
echo '<a href="' . get_category_link( $category->term_id ) . '">' . $category->name . '</a><br/>';
}
?>
https://codex.wordpress.org/Function_Reference/get_categories
Upvotes: 3
Reputation: 3143
it looks like it should be working but did you try any alternative ? like is_category
in if/else
? or try exclusion by category slug
instead of IDs for sake of debugging....
WP Codex Reference for is_category
Upvotes: 0