Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added option to show empty terms #36010

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/block-library/src/categories/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@
"showOnlyTopLevel": {
"type": "boolean",
"default": false
}
},
"showEmpty": {
"type": "boolean",
"default": false
}
},
"supports": {
"align": true,
Expand Down
10 changes: 8 additions & 2 deletions packages/block-library/src/categories/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@ export default function CategoriesEdit( {
showHierarchy,
showPostCounts,
showOnlyTopLevel,
showEmpty,
},
setAttributes,
} ) {
const selectId = useInstanceId( CategoriesEdit, 'blocks-category-select' );
const { categories, isRequesting } = useSelect(
( select ) => {
const { getEntityRecords, isResolving } = select( coreStore );
const query = { per_page: -1, hide_empty: true, context: 'view' };
const query = { per_page: -1, hide_empty: ! showEmpty, context: 'view' };
if ( showOnlyTopLevel ) {
query.parent = 0;
}
Expand All @@ -46,7 +47,7 @@ export default function CategoriesEdit( {
] ),
};
},
[ showOnlyTopLevel ]
[ showOnlyTopLevel, showEmpty ]
);
const getCategoriesList = ( parentId ) => {
if ( ! categories?.length ) {
Expand Down Expand Up @@ -154,6 +155,11 @@ export default function CategoriesEdit( {
checked={ showOnlyTopLevel }
onChange={ toggleAttribute( 'showOnlyTopLevel' ) }
/>
<ToggleControl
label={ __( 'Show empty terms' ) }
checked={ showEmpty }
onChange={ toggleAttribute( 'showEmpty' ) }
/>
{ ! showOnlyTopLevel && (
<ToggleControl
label={ __( 'Show hierarchy' ) }
Expand Down