Make WordPress Core

Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#40059 closed defect (bug) (duplicate)

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

Reported by: backups's profile 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
8 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
8 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 user get_posts() instead of custom SQL queries.

We're already tracking this issue in #29319.

Version 0, edited 8 years ago by SergeyBiryukov (next)
Note: See TracTickets for help on using tickets.