I would suggest that you scrap everything that you have and go back to the default loop on your archive page. Custom queries are always troublesome on archive pages.
Use pre_get_posts
to alter the query vars before the main query is executed. This way, you won’t have any unnecessary queries and problems with pagination. You are going to make use of a tax-query here to include your two terms. For all available parameters for use in pre_get_posts
, see WP_Query
Here is my idea
-
As said, return to the default loop in your archive page
-
In your functions.php, add the following using
pre_get_posts
and the conditional checkis_archive()
. This code will add the two desired terms to your archive pagefunction custom_archive_query( $query ) { if ( !is_admin() && $query->is_archive() && $query->is_main_query() ) { $query->set( 'posts_per_page', 9 ); $query->set( 'post_type', 'any' ); $tax_query = array( 'relation' => 'OR', array( 'taxonomy' => 'event_cat', 'field' => 'slug', 'terms' => 'events', ), array( 'taxonomy' => 'category', 'field' => 'term_id', 'terms' => '7', ), ); $query->set( 'tax_query', $tax_query ); } } add_action( 'pre_get_posts', 'custom_archive_query' );
-
As for the styling issue, on your archive page inside the loop, use the two conditionals,
has_category()
andhas_term
to check to which term a post belongs, and according to that, style itif( has_category( 7 ) ) { // DO SOMETHING FOR CATEGORY }elseif( has_term( 'events', 'event_cat' ) ) { // DO SOMETHING FOR TERM event_cat }
PLEASE NOTE: This is all untested
EDIT
You can do the exact same thing as above using WP_Query
as well