简体   繁体   中英

wordpress: wp_list_categories order by is not working at all

Context: Using Wordpress with jigoshop plugin

I am using wp_list_categories to bring product categories that working well and brings the required list. The only problem is the ordering of the categories. I have used several orderby options (name, ID, slug) but the list order remains still the same as follows:

Tools & Brushes Makeup Remover & Primer Powder Lips Highlighter Foundation Eyes Concealer Bronzer Blush

The jigoshop widget has following code:

$args = array(
    'orderby'       => 'name',
    'show_count'    => $count,
    'hierarchical'  => $is_hierarchial,
    'taxonomy'      => 'product_cat',
    'title_li'      => null,
);
wp_list_categories(apply_filters('widget_product_categories_args', $args));

I am going to replace it by adding filter:

add_filter('widget_product_categories_args','myFun');
function myFun($out){
    .......
    .......
    $args = array(
    'orderby'            => 'name',
    'order'              => 'ASC',
    'style'              => 'list',
    'show_count'         => 0,
    'hide_empty'         => 0,
    'child_of'           => $topMostParent,
    'hierarchical'       => 1,
    'title_li'           => '',
    'current_category'   => $cur_cat,
    'taxonomy'           => $taxonomyName,
);  
return $args;
}

I have tried by deactivating other plugins too but got no effect on result. Please help. Thanks.

Most likely,
Somewhere another filter is changing the arguments these can be.
In order they are executed:

  • get_categories_taxonomy
  • get_terms_args
  • get_terms
  • get_terms_orderby <-- most likely?
  • list_terms_exclusions
  • get_terms_fields
  • terms_clauses
  • get_terms (again)
  • get_terms (again again)
  • wp_list_categories

These are divided over 3 primary functions ( functions which are likely to affect the outcome)

  • wp_list_categories
    • get_categories
      • get_terms

I suggest starting with the get_terms_orderby filter.

If that doesn't work I would try to use the function get_terms That way you will at least know if at which level it goes wrong.

Hopes this helps, let me know ;)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM