Wordpress WP_Query 'orderby' not working
25,114
I have checked your code on my test blog. And it works as expected. So parameters
'orderby' => 'title',
'order' => 'DESC'
you have set correctly.
In this situation you can check SQL request.
$query = new WP_Query($args);
var_dump($query->request);
Author by
Admin
Updated on June 29, 2020Comments
-
Admin almost 4 years
My query is not ordering my posts using the
orderby
parameter.A little background:
I'm within a foreach statement that loops through a custom taxonomy for "category" IDs. while in that foreach statement, I am attempting to invoke a new WP_Query getting posts from each "category" of that foreach loop. My args array is as follows:
$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 both arrays from my custom taxonomies in this post_type.orderby
andorder
are not working at all and I cannot figure this out why.