How can I hide certain posts in the archive?

In some cases it makes sense to display certain posts on the blog page, but not in the archive.

Solution: First, the posts in question should be assigned to a specific category. The following script will then remove this category from the archive. The ID in the script must then be replaced with the created category ID.

function exclude_stuff($query) {
if ( $query->is_date) {
$query->set('cat', '-6');
}
return $query;
}
add_filter('pre_get_posts', 'exclude_stuff');
Without cookies
This website does not use cookies or tracking. More information can be found in the privacy policy.