Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wordpress WP_Query 'orderby' not working

Tags:

sql

php

wordpress

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 and order are not working at all and I cannot figure this out why.

like image 254
Vincent Listrani Avatar asked Nov 19 '12 17:11

Vincent Listrani


1 Answers

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);
like image 73
Vladimir Avatar answered Nov 08 '22 15:11

Vladimir