Forums

MySQL query / Need list of subcategories (6 posts)

  1. areimann
    Member
    Posted 10 months ago #

    I am looking for the query to just list the subcategories (or children) of wp_terms.term_id = 41

    I need to format these is a very odd structure.

    Can anyone help?

  2. filosofo
    Member
    Posted 10 months ago #

    Why not use the WordPress API?

    $descendants = get_categories(array('child_of' => 41));

    $children = get_categories(array('parent' => 41));

    Note that $children will contain just the immediate child categories, but $descendants will include all descendant categories, including grand-children, great-grandchildren, etc.

  3. areimann
    Member
    Posted 10 months ago #

    That sounds great, thanks. But how do I echo that list?

    $children = get_categories(array('parent' => 41));
    foreach ($children as $child) {
    echo $child->cat_name;
    }

    doesn't do anything...what am i missing?

  4. filosofo
    Member
    Posted 10 months ago #

    That should work. Try var_dump($children); to see if anything's being returned.

  5. areimann
    Member
    Posted 10 months ago #

    Thanks...that did work....but not on my local box (didn't have an children there....) oops!

    thanks

    everything works

  6. brockangelo
    Member
    Posted 8 months ago #

    Thanks - this is exactly what I was looking for.

Reply

You must log in to post.

About this Topic