Skip to content

Categories: Apply the legacy Categories widget filters - #85472

Open
dhruvikpatel18 wants to merge 2 commits into
WordPress:trunkfrom
dhruvikpatel18:enhance/categories-block-widget-filters
Open

dhruvikpatel18 wants to merge 2 commits into
WordPress:trunkfrom
dhruvikpatel18:enhance/categories-block-widget-filters

Conversation

@dhruvikpatel18

Copy link
Copy Markdown
Member

What?

Closes #40495.

The Categories block now applies the widget_categories_args and widget_categories_dropdown_args filters from the legacy Categories widget when it lists categories, so filters written for the widget also affect the block.

Why?

Sites that moved from the Categories widget to the Categories block lost the ability to change the block's output with these filters, for example to exclude categories or show empty ones. There was no other way to change the arguments the block passes to wp_list_categories() and wp_dropdown_categories().

Other blocks that replaced a legacy widget already reuse its filters: the Archives block applies widget_archives_args and widget_archives_dropdown_args, and the Latest Comments block applies widget_comments_args. The Categories block was the exception.

Testing Instructions

  1. Add a mu-plugin (for example, wp-content/mu-plugins/categories-filters.php) with:
    <?php
    function test_categories_filters( $args ) {
    	$args['exclude']    = array( 1 );
    	$args['show_count'] = true;
    	return $args;
    }
    add_filter( 'widget_categories_args', 'test_categories_filters' );
    add_filter( 'widget_categories_dropdown_args', 'test_categories_filters' );
  2. Make sure at least one category besides Uncategorized has a published post, and that a tag is assigned to a published post.
  3. Add a Categories block to a page and view the page on the front end. Uncategorized (ID 1) is no longer listed, and the other categories show post counts. On trunk, Uncategorized is listed and there are no counts.
  4. Turn on "Display as dropdown" and view the page again. The dropdown also leaves out Uncategorized and shows post counts.
  5. Change the block's taxonomy to Tags, both as a list and as a dropdown. Tags are listed without counts, because the widget filters are not applied to other taxonomies.

Use of AI Tools

This PR was authored with the help of Claude Code.

@dhruvikpatel18 dhruvikpatel18 self-assigned this Oct 23, 2026
@github-actions github-actions Bot added the [Package] Block library /packages/block-library label Oct 23, 2026
@github-actions

github-actions Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

🤖 PR meta 🤖

Preview in WordPress Playground

🎉 Props

Unlinked Accounts

The following contributors have not linked their GitHub and WordPress.org accounts: @cdils, @noumaan.

Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Unlinked contributors: cdils, noumaan.

Co-authored-by: dhruvikpatel18 <dhruvik18@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Updated as activity occurs, without notifying anyone named here. Add the props-bot label to refresh.

@dhruvikpatel18 dhruvikpatel18 added [Type] Enhancement A suggestion for improvement. [Block] Categories Affects the Categories Block labels Oct 23, 2026
@dhruvikpatel18
dhruvikpatel18 marked this pull request as ready for review October 23, 2026 17:34

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Block] Categories Affects the Categories Block [Package] Block library /packages/block-library [Type] Enhancement A suggestion for improvement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Filter to Modify Output of Categories Block

1 participant