Site logo

Archived topic

Calendar for specific category

3 replies · Started by Masud on February 24, 2023

Viewing posts 1–4 of 4

Currently the calendar showing all category posts. How to show only a specific category post?

Hi there,

which calendar ? Can you share a link to where i can see this on your site ?

I'm actually using Widget > Calendar -

OK, so that generates links to date archives.
And you can use a PHP Snippet to set the cat query to the ID of a single category:

function exclude_category_from_archives( $query ) {
    if ( $query->is_date() && $query->is_main_query() ) {
        $query->set( 'cat', '99' );
    }
}
add_action( 'pre_get_posts', 'exclude_category_from_archives' );

Replace 99 with the id of your category.

NOTE: This will not change what the calender displays, that is a core Block, and they did not add any filters hooks ( to my knowledge ) to change what it displays.

This archived topic is closed to new replies.