On my blog’s archive page if I click on a month, it takes me to a page showing me all the posts that I’ve created that month (obviously). Is there a way to filter that page so it only shows me posts from one of my categories?
archive.php
<?php if ( have_posts() ) : ?>
<div class="rightColumn">
<?php
while ( have_posts() ) : the_post();
get_template_part( 'content', get_post_format() );
endwhile;
// Previous/next page navigation.
twentyfourteen_paging_nav();
else :
get_template_part( 'content', 'none' );
endif;
?>
</div>
<?php
get_footer();
Thanks.
I ended up finding a solution that worked for me:
try using the
pre_get_posts
hook, something along the lines of:you can drop this code into your functions.php file
you can find more info about the
pre_get_posts
hook hereThat simple hook helped me too. I modified the function a little to get the category Id from $_GET:
No filters or hooks necessary. Just pass the category you want to filter for in the URL.
With an ID
https://myblog.com/2018/?cat=1234
With a slug
https://myblog.com/2018/?category_name=my-category-slug