How to sort Woocommerce Order’s products by product description in WP_Query
-
I am currently using WP All Export Pro and using WP_Query to pull only the last Woocommerce order completed. This is the code:
function example_get_those_ids($post_type = ‘post’, $number_of_posts = 5, $order = ‘ASC’, $post_status = ‘publish’, $order_by = ‘ID’) {
$query = get_posts(
array(
‘post_type’ => $post_type,
‘numberposts’ => $number_of_posts,
‘order’ => $order,
‘orderby’ => $order_by,
‘post_status’ => $post_status,
‘fields’ => ‘ids’
)
);return ( !empty($query) ) ? $query : array();
}And then running this in the query.
‘post_type’ => ‘shop_order’, ‘post_status’ => ‘wc_completed’, ‘post__in’ => example_get_those_ids(‘shop_order’, ‘1’, ‘DESC’, ‘wc_completed’)
I was wondering how I can then go ahead and sort the products in that query by product description or a custom product field if possible.
Thank you.
- The topic ‘How to sort Woocommerce Order’s products by product description in WP_Query’ is closed to new replies.