get_terms – only top level

Your code is correct, well almost correct. On first view, I must confess, I missed it too.

You have two syntax errors in your code. If you look closely, 'parent ' and 'parent' is not the same. You should not leave blank spaces between single quotes (') and arguments.

Also, you don’t need to add a , after your last argument.

This should work

$cat_args = array(
    'parent'        => 0,
    'number'        => 10,
    'hide_empty'    => false           
);

EDIT 15-06-2016

As from WordPress 4.5, the syntax has changed for get_terms(). The taxonomy parameter is now included in the array or args, so the new use will look like this

$args = [
    'taxonomy'     => 'my_tax',
    'parent'        => 0,
    'number'        => 10,
    'hide_empty'    => false           
];
$terms = get_terms( $args );

Leave a Comment