WordPress.org

Make WordPress Core

Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#40059 closed defect (bug) (duplicate)

Exclude a category site wide creates a 404 on calendar widget next month

Reported by: BackuPs Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.7.3
Component: General Keywords:
Focuses: Cc:

Description

Hi

When you exclude a category site wide and suppose for this problem the month before this month has only ONE post and that post is excluded as it is part of the excluded category, then the calendar widget is still showing the next month as FEB and thus is still pointing to that month but when clicked upon it creates a 404 page. It should point to Jan and skip the month with that one post which is excluded.

How to prevent this from happening? Is there a fix?

<?php
function exclude_blog_category_global( $query ) {
        
        if (!is_admin() ) {
                if (is_archive()) {
                                $exclude='-5';
                                if (!empty($exclude)) {
                                        $query->set( 'cat', $exclude );
                                }
                }

        }
}
add_action( 'pre_get_posts', 'exclude_blog_category_global' );

If i use query_posts in the archive php all is ok but when reading the codex it is suggested to use the pre_get_posts on main queries.

How to fix this? tested with Default sixteen template.

Change History (2)

#1 follow-up: @BackuPs
3 years ago

Looking into general-template.php i can see that the previous and next do not take into account for excluded categories. There is also no filter to add excluded categories into the arguments passed to the query.

#2 in reply to: ↑ 1 @SergeyBiryukov
3 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Hi @BackuPs, thanks for the ticket!

Looking into general-template.php i can see that the previous and next do not take into account for excluded categories. There is also no filter to add excluded categories into the arguments passed to the query.

That's right, the calendar should be switched over to use get_posts() instead of custom SQL queries.

We're already tracking this issue in #29319.

Last edited 3 years ago by SergeyBiryukov (previous) (diff)
Note: See TracTickets for help on using tickets.