I have a working query which returns a set of custom posts which are ordered by their package ID (ASC). For a query with 9 results this may return for example:
4 posts (Post ID's 1,2,3,4) with Package ID 1
3 posts (Post ID's 5,6,7) with Package ID 2
2 posts (Post ID's 8,9) with Package ID 3
When these posts are displayed they are always in the same order. In other words, they are displayed in order from Post ID 1 to Post ID 9.
What I am trying to achieve is to sort the results of each subset (defined by Package ID) randomly. In this way the posts would be displayed as such:
Random display of Post ID's 1 through to 4 (eg 2,1,4,3)
Random display of Post ID's 5 through to 7 (eg 6,5,7)
Random display of Post ID's 8 through to 9 (eg 8,9)
So the posts are still grouped by the Package ID but the posts within each package are displayed randomly.
This is how my current query looks:
$args = array(
'post_type' => 'custom_post_type',
'post_status' => 'publish',
'posts_per_page' => 9,
'meta_key' => 'pkg_id',
'orderby' => 'pkg_id',
'order' => 'ASC'
);
What I thought 'might' work but doesn't:
$args = array(
'post_type' => 'custom_post_type',
'post_status' => 'publish',
'posts_per_page' => 9,
'meta_key' => 'pkg_id',
'orderby' => array( 'pkg_id' => 'ASC', 'rand' )
);
Any suggestions as I am completely stumped!