I’d like to display a list of products for a certain category, sorted by the post_excerpt.
The original code I used was this:
$args = array(
'tax_query' => array(
array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => array( 'my-product-category' ),
'operator' => 'IN'
)
),
'orderby' => 'post_excerpt',
'order' => 'ASC'
);
$loop = new WP_Query( $args );
This displays the products, but the orderby is ignored in a taxonomy query. So I’ve changed the query to:
$args = array(
'post_type' => 'product',
'orderby' => 'post_excerpt',
'order' => 'ASC',
'product_cat' => 'My Product Category',
'post_status' => 'publish'
);
$loop = new WP_Query( $args );
The products are displayed, but the orderby clause is still ignored.
If you take a look at the WordPress Codex ‘post_excerpt’ is not a valid parameter for the ‘orderby’ parameter
For this reason it cannot be done through WP_Query(). If you don’t mind, why are you trying to sort by post_excerpt in the first place?
Now, you can use filter posts_orderby.