Support » Fixing WordPress » Getting JUST the top-level category names (parent)

  • wp: latest
    theme: notorious

    In the backend, I have a section called portofolio, with few categories as follows: drinks, food, whatever.

    In each one of these I’ve got two or three more subcategories and the subcategories all have few posts.


    -bla bla

    Now, on the portfolio page I have this foreach to get the top level category names out but my function:

    $terms = get_terms('portfoliocategory', 'hide_empty=1&pad_counts=1&child_of=0'); $count = count($terms);

    ..gets out the names of each category and sub-category. I only need the top-level ones (without alterating the structure tree of these categories).

    What function should I use, what arguments, any examples/hints please? I think I have tried everything.

    Thank you.

    and part of my foreach:

    foreach ( $terms as $term ) {
    echo '<li class="'.$term->name.'">
    <a class="portfoliobutton_noselect" href="#">'.$term->name.'</a></li>';} ETC, ETC

Viewing 2 replies - 1 through 2 (of 2 total)
  • Have a look at the Codex

    (integer) Get direct children of this term (only terms whose explicit parent is this value). If 0 is passed, only top-level terms are returned. Default is an empty string.




    Thanks David, I’ve tried that argument aswell, doesn’t work as it only gets the top level categories which have no subcategories at all.

    If there is a parent category without any sub-categories in it, whether empty or not, it will not display.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Getting JUST the top-level category names (parent)’ is closed to new replies.