Introduction

By design, the archives page template pulls in all posts and displays their categories in the right column. If you want to modify this template to display your tag archives, you must change the query.

To exclude categories, please consider using the Simply Exclude  plugin instead.

The Solution

 

To get the archives.php to display only specific categories, you need to change the query on line 5:

$fetch_archive = $wpdb->get_results("SELECT * FROM " . $wpdb->posts . " WHERE post_status='publish' AND post_type = 'post' GROUP BY $wpdb->posts.ID ORDER BY post_date DESC");

Replace the above with this query. I have reformatted it so you can see what each line is doing:

$fetch_archive = $wpdb->get_results("
SELECT *
FROM " . $wpdb->posts . "
LEFT JOIN $wpdb->term_relationships ON($wpdb->posts.ID = $wpdb->term_relationships.object_id)
LEFT JOIN $wpdb->term_taxonomy ON($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)
LEFT JOIN $wpdb->terms ON($wpdb->term_taxonomy.term_id = $wpdb->terms.term_id)
WHERE $wpdb->term_taxonomy.term_id IN(1,2,3)
AND $wpdb->term_taxonomy.taxonomy = 'category'
AND post_status='publish'
AND post_type = 'post'
GROUP BY $wpdb->posts.ID
ORDER BY post_date DESC");

On the WHERE line, replace the red category IDs with the ids corresponding to the categories you want to appear. To get the ID, you can either install Admin Managment Xtended or hover over the category link under Posts > Categories to see the “Tag_ID in the status bar of your browser.

 

Elementor