i have in all of my posts an additional custom field (acf user field) in case the post has a co-author.
All users have their own author-page where all their posts are displayed. No problem so far.
But what i now want is a query where i get all posts where the author is the actual author and all posts where he/she is just the co-author in the custom field.
My code is pretty simple so far, but did not actually work. I guess the ‘relation’ parameter is only for comparing meta query-subarrays.
$args = array(
'post_type' => array( 'post' ),
'posts_per_page' => 20,
'relation' => 'OR',
array(
'author' => $author_ID,
),
array(
'meta_key' => 'authorfeld',
'meta_value' => $showme[ID], // This is the authors id from the custom field
)
);
Thank you
2 Answers
I found some hints here: Can i merge 2 new WP_Query($variable) ‘s?
So i created two separate queries and merged them into a new array:
$wp_query = new WP_Query();
$wp_query->posts = array_merge( $query1->posts, $query2->posts );
foreach($wp_query->posts as $post) :
setup_postdata( $post );
And then the usual stuff.