WordPress.org

Forums

get_category misbehaving (2 posts)

  1. dezynworks
    Member
    Posted 2 years ago #

    When I run get_categories() I get back a list of all my categories, one of which is:

    [1] => stdClass Object
            (
                [term_id] => 7
                [name] => California
                [slug] => california
                [term_group] => 0
                [term_taxonomy_id] => 7
                [taxonomy] => category
                [description] =>
                [parent] => 6
                [count] => 2
                [cat_ID] => 7
                [category_count] => 2
                [category_description] =>
                [cat_name] => California
                [category_nicename] => california
                [category_parent] => 6
            )

    However, if I run

    $args = array( parent => 6 );
    get_categories( $args );

    I get nothing. If I set parent to zero I get the root categories as expected, but zero is the only value that returns anything. I'm totally at a loss. I've tried every combination of hierarchical & hide_empty, but I can't get any results out of get_categories besides all categories or just root categories. What am I missing? This is making me crazy.

    -Dez

  2. Drew Jaynes
    4.2 Release Lead
    Posted 2 years ago #

    Hi dezynworks,

    Make sure the parent parameter in your $args array is in single quotes, e.g.

    $args = array( 'parent' => 6 );

    It's also possible for one reason or another, you might need to test against the category_parent parameter instead. So maybe:

    $args = array( 'category_parent' => 6 );

Topic Closed

This topic has been closed to new replies.

About this Topic