I have a category archive page (press), which I need to loop through posts of a certain tag (magazines). I tried to modify the query with pre_get_posts, but it is still just showing posts in the ‘press’ category. I got this to work with a custom query setting the tag in $args
, but then I lose pagination.
To clarify, posts with the tag ‘magazine’ may or may not have the category ‘press’, and I need to loop through EVERY post with the tag ‘magazine’.
Is there anything wrong with my code? Ideas how to accomplish this?
function tag_loop( $query ) {
if ( $query->is_category() && $query->query_vars['cat'] == 'press' && $query->is_main_query()) {
$query->set( 'tag', 'magazine' );
}
}
add_action( 'pre_get_posts', 'tag_loop' );