In a Looper using the Query Builder, is it possible to sort by multiple values? For example, I want to sort by Age and then by Title. I have the Order By field setup to sort by Age, but now how can I get it to sort by title within each age?
Hello @dannikb,
Thanks for writing to us.
You have multiple orders by parameter since the “orderby” query parameter accepts the array where you can add multiple parameters.
To achieve it using the Looper you need to set the Looper provider as a Query String
$args = array(
'post_type' => 'your_cpt',
'orderby' => array( 'meta_value_num' => 'ASC', 'title' => 'ASC' ),
'meta_key' => 'your_meta_key'
);
Query String would be like this.
post_type=your_cpt&orderby%5Bmeta_value_num%5D=ASC&orderby%5Btitle%5D=ASC&meta_key=your_meta_key
Hope it helps
Thanks
Thank you. I was aware that you could accomplish it via Query String, but was hoping for a solution using the Query Builder. Unfortunately, I haven’t had much luck with the Query String option. My query is fairly complex and involves dates, and I’ve not been able to get it to work correctly.
Hey Danni,
You can try this WP query generator that might help you build your query string.
Hope that helps.
This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.