Wordpress WP_Query 'orderby' not working

My request does not order my messages using the orderby parameter.

A bit of background:

I enter the foreach statement, which goes through a custom taxonomy for category identifiers. while in this foreach statement, I'm trying to call a new WP_Query that receives messages from each "category" of this foreach loop. My args array looks like this:

 $args = array( 'post_type' => 'wpsc-product', 'post_status' => 'publish', 'showposts' => -1, 'tax_query' => array( array( 'taxonomy' => 'wpsc_product_category', 'field' => 'term_id', 'terms' => $cat_id, ), array( 'taxonomy' => 'series', 'field' => 'slug', 'terms' => $series_name ) ), 'orderby' => 'title', 'order' => 'DESC' ); 

$cat_id and $series_name are arrays of my custom taxonomies in this post_type.

orderby and order do not work at all, and I cannot understand why.

+6
source share
1 answer

I checked your code on my test blog. And it works as expected. Thus, the parameters

 'orderby' => 'title', 'order' => 'DESC' 

You installed it correctly.

In this situation, you can check the SQL query.

 $query = new WP_Query($args); var_dump($query->request); 
+11
source

Source: https://habr.com/ru/post/1447036/


All Articles