How to create a completely functioning separate archive for posts from only 1 or 2 specific categories
I can't seem to find a complete way of resolving my issue. I've found parts, but it seems I'm the only one out there who has the issue I do.
I have a web working with WP, and recently I've been asked to include a blog within the web. For the authors' ease, I decided to go about doing that by creating a specific category for the blog, so all they have to do to publish in the blog is chose a category. The "blog" sections is aesthetically different, so as to give the user an idea that this is separate from the rest of the web. And obviously they need an archive, like the ones in blogs, ex.:
- January 2018 (3)
- February 2018 (2)
- March 2018 (5) ...
Which I've managed by including this in the functions.php:
add_filter( 'getarchives_where', 'wse95776_archives_by_cat', 10, 2 );
/**
* Filter the posts by category slug
* @param $where
* @param $r
*
* @return string
*/
function wse95776_archives_by_cat( $where, $r ){
return "WHERE wp_posts.post_type = 'post' AND wp_posts.post_status = 'publish' AND wp_terms.slug = 'BLOGCATEGORY' AND wp_term_taxonomy.taxonomy = 'category'";
}
add_filter( 'getarchives_join', 'wse95776_archives_join', 10, 2 );
/**
* Defines the necessary joins to query the terms
* @param $join
* @param $r
*
* @return string
*/
function wse95776_archives_join( $join, $r ){
return 'inner join wp_term_relationships on wp_posts.ID = wp_term_relationships.object_id inner join wp_term_taxonomy on wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id inner join wp_terms on wp_term_taxonomy.term_id = wp_terms.term_id';
}
Which basically limits the the posts shown in the archive to only those that are in the BLOGCATEGORY. And then I echo the archive out wherever I want it using:
echo 'ul class="blog-archive"li'.wp_get_archives( array( 'type' = 'monthly', 'format' = 'li', 'show_post_count' = 1, 'include'=1 ) ).'/li/ul';
Up to that point, everything is working perfectly, and we get the archive structure I shoed above. However, when a user clicks on one of the archive links in order to see, for example, all of the 3 posts from January 2018, they're taken into a page that gathers all posts from January 2018, i.e. the 3 that belong to the blog category but all other posts in the website, no matter the category.
So basically my question is how do I obtain a completely functioning separate archive for posts for only one or two specific categories?
Topic archive-template wp-get-archives custom-taxonomy archives Wordpress
Category Web