Yes, this can be done, but it’s quite some work, so I’m only going to give you the outline:
First, if you look at the last example under taxonomy parameters of wp_query
you will see that you can query post formats as a taxonomy. So you would look at something like this (untested) to get all posts in the link and quote formats:
$args = array(
'post_type' => 'post',
'tax_query' => array(
'relation' => 'OR',
array(
'taxonomy' => 'post_format',
'field' => 'slug',
'terms' => array( 'post-format-link' ),
),
array(
'taxonomy' => 'post_format',
'field' => 'slug',
'terms' => array( 'post-format-quote' ),
),
),
);
$query = new WP_Query( $args );
At this point, there are still two things to do: order the array so the link format post comes first, and limit the amount of posts to 1 from link and 3 from quote formats. Unfortunately, ordering by taxonomy in a query is not directly supported. This also makes it difficult to select amounts of post per post format. The easiest way to solve this is by looping through $query
twice using rewind_posts
:
// Get one post with format link
while ($query->have_posts()) {
$i=0;
if (has_post_format('link') && $i<1) {
// do your thing
$i = $i+1;
}
}
$query->rewind_posts();
// Get three posts with format quote
while ($query->have_posts()) {
$i=0;
if (has_post_format('quote') && $i<3) {
// do your thing
$i = $i+1;
}
}
Note that you would still have to add some logic to account for cases where there are not enough posts to show.