Satch3000 Satch3000 - 2 years ago 205
PHP Question

woocommerce products category order

I have created a template and I'm using the code to show the product categories on a page:

<?php $wcatTerms = get_terms('product_cat', array('hide_empty' => 0, 'orderby' => 'ASC', 'parent' =>0)); //, 'exclude' => '17,77'
foreach($wcatTerms as $wcatTerm) :
$wthumbnail_id = get_woocommerce_term_meta( $wcatTerm->term_id, 'thumbnail_id', true );
$wimage = wp_get_attachment_url( $wthumbnail_id );

When I change the order in the backend it won't change.

How can I hard-code the order or set it to order by id?

d79 d79
Answer Source

You confused orderby with order, they're 2 different arguments (see get_terms):

$wcatTerms = get_terms('product_cat', array(
    'hide_empty' => 0, 
    'orderby'    => 'id',
    'order'      => 'ASC',
    'parent'     => 0
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download