I am building a website where certain users will be "premium" and certain users will be non premium. Both roles will be able to make posts, but in our post queries, we would like all posts made by "premium" users to be returned first, with a css class of "premium", and then all non-premium posts returned after.
I need to do so in a way that preserves pagination.
I have the following query which I can use to return posts by user role:
<?php $premiums = get_users( array( 'role' => 's2member_level1, administrator' ) );
$premium_ids = array();
foreach( $premiums as $premium )
$premium_ids[] = $premium->ID;
$posts = new WP_Query( array( 'author' => implode( ',', $premium_ids ), 'post_type' => 'classifieds', 'paged' => get_query_var('paged') ) );
if ( $posts->have_posts() ) : while ( $posts->have_posts() ) : $posts->the_post();
// The post title, content, etc, encase in a PREMIUM css class
endwhile;
endif;
wp_reset_postdata(); ?>
The two roles specified above are our "premium" roles so all their posts should be returned first. The non premium roles use the "subscriber" role provided in WordPress.
For the non-premium posts, I was going to do a second query swapping out the role as needed, but I realized this would break pagination, or at least stop pagination from working in the traditional way.
Therefore, it seems to be clear that I need to have everything in a single query.
From reading posts such as the following, I know its possible to merge two queries into one, but I am not sure if this would be the best way to go.
https://wordpress.org/support/topic/multiple-queries-compiling-into-one-loop
Therefore, I am posting the question here to see if anyone might know of a way to query our premium users, return their posts, then query the non premium users and return their posts, all in one single query with a "premium" class on premium posts and a "non-premium" class on the non premium ones.
This is more of a PHP issue than a WordPress one I feel, so I have tagged this question as PHP first and WordPress second.
Hope someone can help.
Thanks