WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] WP list categories trouble (2 posts)

  1. Josh Levinson
    Member
    Posted 1 year ago #

    I am using wp_list_categories to try to get a parent-level listing of WooCommerce categories.

    My code is as such:

    $cat_args = array('taxonomy' => 'product_cat');
    $cat_args['menu_order'] = false;
    $cat_args['orderby'] = 'title';
    $cat_args['title_li'] = '';
    $cat_args['depth']=1;

    However, the function still returns child-level product categories. Am I using this function improperly? All the evidence says no.

    It appears that the sql query being executed is
    SELECT t.*, tt.* FROM wp_terms AS t INNER JOIN wp_term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.taxonomy IN ('product_cat') AND ( t.term_id <> 1 AND t.term_id <> 1 ) AND tt.count > 0 ORDER BY t.name ASC

  2. Josh Levinson
    Member
    Posted 1 year ago #

    Found the solution - the hierarchical flag MUST be on for these parameters to take effect. This was not made apparent in the codex.

    However - I think this raises a good question: is there a good reason that the hierarchical flag must be on to make the depth parameter take effect? In my case, I don't care about hierarchy, I just want to display the top-level categories, those with no parent.

Topic Closed

This topic has been closed to new replies.

About this Topic