Make WordPress Core

Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#29850 closed defect (bug) (invalid)

Theme Function Filter disables Admin Dashboard Post Filter

Reported by: antonv's profile antonv Owned by:
Milestone: Priority: normal
Severity: minor Version: 3.9.2
Component: Query Keywords:
Focuses: administration Cc:


I have following filter in my theme functions.php to exclude post from an Archive Widget:

function exclude_category($query) {
if ( $query->is_archive ) {
$query->set('cat', '-26,-1,-57,-58');
return $query;
add_filter('pre_get_posts', 'exclude_category');

However, this disables the filter by category on the Posts-page (../wp-admin/edit.php). Removing above code from theme functions.php the Post-page filter works as it is intended to do. This is new as the Posts-page filter used to work on an earlier version of WP with above code in the theme functions.php.

Surely theme filters should not take precedence over the wp-admin pages.

Change History (2)

#1 @antonv
10 years ago

  • Severity changed from normal to minor

#2 @SergeyBiryukov
10 years ago

  • Component changed from General to Query
  • Focuses administration added
  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed

'pre_get_posts' runs in the admin too. You should add an is_admin() check to your function.

It's also a good idea to add a $query->is_main_query() check.

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