[wp-trac] [WordPress Trac] #40059: Exclude a category site wide creates a 404 on calendar widget next month

WordPress Trac noreply at wordpress.org
Tue Mar 7 11:54:57 UTC 2017


#40059: Exclude a category site wide creates a 404 on calendar widget next month
--------------------------+-----------------------------
 Reporter:  BackuPs       |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  General       |    Version:  4.7.3
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 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
 <?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.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/40059>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list