Your title is
wp_get_post_terms Order by not working
but if you use a custom post type you need to use wp_get_object_terms()
I’m not sure what your aim is, but here is a code example you can try:
$my_post_type="post"; // edit this
$my_taxonomy="category"; // edit this
$my_query = new WP_Query(array('post_type' => $my_post_type,'posts_per_page'=>10));
if ($my_query->have_posts()) :
while ($my_query->have_posts()) : $my_query->the_post();
$product_terms = wp_get_object_terms(get_the_ID(), $my_taxonomy, array('orderby' => 'name', 'order' => 'ASC', 'fields' => 'all'));
if(!empty($product_terms)){
if(!is_wp_error( $product_terms )){
echo '<ul>';
foreach($product_terms as $term){
echo '<li><a href="'.get_term_link($term->slug, $my_taxonomy).'">'.$term->name.'</a></li>';
}
echo '</ul><hr>';
}
}
endwhile;
endif;
ps: I changed your code a bit, so now we use WP_Query()
instead of the non-recommended query_posts()
.
Edit:
Here is an example of the output, where the terms are ordered with name
and ASC
aaa
bbb
ccc
---
aaa
ccc
---
bbb
ccc
and with order DESC
ccc
bbb
aaa
---
ccc
aaa
---
ccc
bbb