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' );
cat
parameter, setting it asnull
for example?$query->query_vars; die();
to see which parameter is being used to set the category... did you try that yet? If you do that and don't know what to do next, just paste the content as a edit to you original question :)