EDIT: I made some research and this is where I stand now:
I'm using custom post types to let users add own content to my site. The user could also sign a paid membership (made with WooCommerce Membership plugin). This process works very well.
Now I want to display all the posts from the users in an overview. Starting with posts from paying members.
Membership plans and signed memberships are stored as custom post types. The user of a signed membership is also the post author.
So I guess I need to use the membership users/authors in the loop for my post types. To do this I've a loop which returns all author IDs of active memberships and store them in an array. The code looks like this:
<ul>
<?php
$posts = get_posts( array(
'post_type' => 'wc_user_membership',
'post_status' => array('wcm-active'),
'numberposts' => -1,
) );
$ids = array();
foreach ( $posts as $post ) :
setup_postdata( $post ); ?>
<?php
$post_author_id = get_post_field( 'post_author', $post_id );
array_push( $ids, get_the_author_meta('ID', $post_author_id) );
?>
<?php endforeach; wp_reset_postdata(); ?>
</ul>
<?php print_r($ids); ?>
And the output looks like this:
Array ( [0] => 545 [1] => 543 [2] => 542 [3] => 538 [4] => 6 )
At the moment, I'm displaying posts separated by the category.
For example: I've 10 categories and I show 6 posts per category before a new post list for the next category begins. This part also works fine.
My code looks like this at the moment:
<?php
// Here I get the terms to display
$post_type_categories = get_terms( 'post_type_category' );
?>
<ul class=" list-unstyled">
<?php
// Here I show 6 posts per term from above
foreach ( $post_type_categories as $post_type_category ) {
$post_type_category_query = new WP_Query( array(
'post_type' => 'post_type',
'orderby' => 'date',
'order' => 'DESC',
'posts_per_page' => 6,
'tax_query' => array(
array(
'taxonomy' => 'post_type_category',
'field' => 'slug',
'terms' => array( $post_type_category->slug ),
'operator' => 'IN'
)
)
) );
?>
<li class="mb-5">
<p class="h4"><?php /* Display the term title as headline */ echo $post_type_category->name; ?></p>
<ul class="list-unstyled row">
<?php
// Show posts from the category
// Here I want to display the posts from an author with a specific membership plan (meta data?!) first
if ( $post_type_category_query->have_posts() ) : while ( $post_type_category_query->have_posts() ) : $post_type_category_query->the_post(); ?>
<li class="col-lg-4">
<strong><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute('echo=0'); ?>"><?php the_title(); ?></a></strong>
</li>
<?php endwhile; endif; ?>
</ul>
</li>
<?php $post_type_category_query = null; wp_reset_postdata(); } ?>
</ul>
It displays a list of categories and 6 posts per category.
Is there any way to combine these two loops and show the posts from the members on top?
I guess I need to use the author parameters from the WP_Query (https://codex.wordpress.org/Class_Reference/WP_Query#Author_Parameters) to do so?
I'm able to show only posts from the members but I don't know how to combine these posts and sort them. Also there should not be duplicates in the loop (member posts on top and in the rest of the posts)