Date Archives by Category
-
Hi,
I’m new to WordPress, and I have an issue with the date archive.
On my website, I put the archives widget in the sidebar to show the dates of all my blog posts. Then I used custom code to categorize the archives widget, so when you click on the dates, it only shows the posts in the specific category. Here is the code:
function custom_date_archive_for_category( $query ) { if ( $query->is_date() && $query->is_main_query() ) { $query->set( 'cat', '76' ); } } add_action( 'pre_get_posts', 'custom_date_archive_for_category' );
The code works for what it’s meant to do.
My issue is that the archives widget shows dates of posts that don’t have a specific category assigned to them. I want the archive to only show the dates of the category I assign to it; in my case, it’s the “blog” category.
Is it possible to limit the archives widget so it only shows the dates of the category you choose?
Is there any code available that would help?
- The topic ‘Date Archives by Category’ is closed to new replies.