The design dictated that there be a paginated list of posts that started with posts from the primary category, and then drew from a custom taxonomy. Not going to lie. This was a doozy.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
// set the "paged" parameter (use 'page' if the query is on a static front page)
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
 
// Get the first query - all microsite posts
$posts1 = get_posts(array(
    'category_name' => 'combined',
    'posts_per_page' => -1
));
 
// Get the second query - all posts tagged with microsite
$posts2 = get_posts(array(
    'post_type' => 'post',
    'posts_per_page' => -1,
    'tax_query' => array(
        array(
            'taxonomy' => 'otherposts',
            'field' => 'slug',
            'terms' => 'combined'
        )
    )
));
 
// Combine the queries
$mergedposts = array_merge($posts1, $posts2);
$postids = array();
foreach( $mergedposts as $item ) {
    $postids[] = $item->ID; // Create a new query only of the post ids
}
 
// Create an array of post IDs
$uniqueposts = array_unique($postids);
$args = array(
    'post__in' => $uniqueposts,
    'paged' => $paged,
    'orderby' => 'post__in'
);
 
// Loop through the posts
$the_query = new WP_Query($args);
if ( $the_query->have_posts() ) {
    $checking = 0;
    while ( $the_query->have_posts() ) { $the_query->the_post();
        // Handle posts here
    }
    wp_reset_postdata();
}
?>