• I’m using the following query to display posts marked as ‘premium’ first, like so:

    <?php $query = 'post_type=recruiter-partner&meta_key=premium&orderby=meta_value&paged=' . $paged; ?>

    Although I want the premium posts to show up first, I still want everything ordered by title.

    Is there a simple way to achieve this in the query? Or would I have to re-order it myself?

Viewing 2 replies - 1 through 2 (of 2 total)
  • How about:

    <?php $query = 'post_type=recruiter-partner&meta_key=premium&orderby=meta_value,title&paged=' . $paged; ?>

    If you use WP_Query passing all the arguments in as an array then you can use multiple sort columns like so ‘orderby’ => ‘title menu_order’. If you’re configuring this as a query string then I’d assume rather than separating multiple order columns with spaces you would just separate them with a comma. I haven’t tried it though!

    Thread Starter 000000000

    (@pealo86)

    Genius thanks! The comma solution didn’t work so I used an array instead:

    <?php $query = array(
    	'post_type' => 'recruiter-partner',
    	'meta_key' => 'premium',
    	'orderby' => 'meta_value title',
    	'order' => 'ASC',
    	'paged' => $paged
    ); ?>
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Order a query by meta_value and *then* by title’ is closed to new replies.