Forums

[resolved] how to get to top cat id in an array (5 posts)

  1. storyday
    Member
    Posted 5 years ago #

    how can I get cat id in an array?
    for example
    cat id name
    1 topcat1
    2 ----sub1
    3 -----sub2
    4 topcat2
    5 topcat3
    6 ----sub31

    I want get 1 4 5,what can I do?
    could you help me?thanks!

  2. pianosteve
    Member
    Posted 5 years ago #

    I'm not entirely sure I understand what you're asking. Are you saying you want an array with just the top categories? And are you asking for the MySQL query to obtain that?

  3. storyday
    Member
    Posted 5 years ago #

    Yes I want an array with just the top categories! Either mysql query or WP templates tag is OK!templates tag is preferred

  4. pianosteve
    Member
    Posted 5 years ago #

    I don't think it's possible with template tags (although I don't understand why not). I see no parameters that allow you to just pull top-level categories.

    But the MySQL query would look something like:

    SELECT cat_ID FROM wp_categories WHERE category_parent = 0

    Note that in WP2.1 or greater, this will also retrieve categories for your blogrolls since they rolled that into the wp_categories table in Ella.

    If you want to eliminate those, you would have to a bit more complicated query with joins to another table or two. Do you need that, too?

  5. storyday
    Member
    Posted 5 years ago #

    thank you It seems I should use mysql query,:)

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags