Skip to content

Enhanced query filter blocks with new display types#25

Open
thomasnavarro wants to merge 2 commits intohumanmade:mainfrom
thomasnavarro:main
Open

Enhanced query filter blocks with new display types#25
thomasnavarro wants to merge 2 commits intohumanmade:mainfrom
thomasnavarro:main

Conversation

@thomasnavarro
Copy link

This pull request enhances the query filter blocks for post types and taxonomies by adding support for multiple display types (dropdown, radio, and checkbox) and layout directions (vertical and horizontal). It also includes styling updates and adjusts rendering logic to accommodate the new features.

Enhancements to query filter blocks:

Functional improvements:

  • Added new attributes displayType and layoutDirection to allow customization of the display format (dropdown, radio, or checkbox) and layout orientation (vertical or horizontal) for both post type and taxonomy filters.

Styling updates:

  • Enhanced CSS to support the new layout options, including horizontal and vertical orientations for radio and checkbox groups.

Editor improvements:

  • Modified JavaScript files to integrate the new attributes into the block editor, allowing users to select display type and layout direction via the block settings panel.

Miscellaneous updates:

  • Updated asset files to reflect changes in dependencies and versions.
  • Added .wp-env.json configuration file to simplify local development setup.

Thomas Navarro added 2 commits June 7, 2025 22:40
… direction

- Updated package.json to include @wordpress/env as a dev dependency.
- Added new attributes `displayType` and `layoutDirection` to block.json for post-type and taxonomy blocks.
- Modified the Edit component for post-type and taxonomy blocks to include SelectControl for display type and ToggleGroupControl for layout direction.
- Implemented conditional rendering for select, radio, and checkbox inputs based on the selected display type.
- Updated render.php files for post-type and taxonomy blocks to handle new display type and layout direction attributes.
- Added styles for radio and checkbox groups in style-index.css to support vertical and horizontal layouts.
@sunmorgn
Copy link

sunmorgn commented Mar 3, 2026

Any chance of getting this merged?

Copy link

@goldenapples goldenapples left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've also been wanting to use this feature, so I gave it an initial review. The feature itself looks great to me and I'd like to see it merged.

I see a couple things to update first:

  • The whitespace shouldn't be changing in all the PHP files. There's not currently a PHP coding standard in the project, but for consistency it should follow HM or WordPress coding standards
  • There have been 3 point releases since this PR was opened, and it doesn't apply cleanly on main anymore. We'll have to freshen up the branch and resolve conflicts.
  • I don't think the wp-env environment should be in this same PR, though it it really cool to have. I'd like to merge that separately to better preserve a clean history

I'm happy to take on these updates and get the feature merged, unless anyone sees other issues with it.

<label class="wp-block-query-filter-post-type__label wp-block-query-filter__label<?php echo $attributes['showLabel'] ? '' : ' screen-reader-text' ?>" for="<?php echo esc_attr( $id ); ?>">
<?php echo esc_html( $attributes['label'] ?? $taxonomy->label ); ?>
<div <?php echo get_block_wrapper_attributes(['class' => 'wp-block-query-filter']); ?> data-wp-interactive="query-filter" data-wp-context="{}">
<label class="wp-block-query-filter-post-type__label wp-block-query-filter__label<?php echo $attributes['showLabel'] ? '' : ' screen-reader-text' ?>" for="<?php echo esc_attr($id); ?>">

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class name is updated (from 'post-type' to 'taxonomy') in the src but not here, we'll need to check in the built files.

add_action( 'pre_get_posts', __NAMESPACE__ . '\\pre_get_posts_transpose_query_vars' );
add_filter( 'block_type_metadata', __NAMESPACE__ . '\\filter_block_type_metadata', 10 );
add_action( 'init', __NAMESPACE__ . '\\register_blocks' );
add_action( 'enqueue_block_assets', __NAMESPACE__ . '\\action_wp_enqueue_scripts' );

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't look like this function should be getting removed here, but also this is dead code that's been removed from main so it shouldn't show up in the diff.

Comment on lines +100 to +102
$values = explode(',', $value);
$values = array_map('trim', $values);
$values = array_filter($values);
Copy link

@goldenapples goldenapples Mar 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be simpler with wp_parse_list:

Suggested change
$values = explode(',', $value);
$values = array_map('trim', $values);
$values = array_filter($values);
$values = wp_parse_list($value);

?>
<?php foreach ($terms as $term) : ?>
<?php
$is_checked = in_array($term->slug, $selected_terms);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May as well pass strict: true here to pass common lint standards.

Suggested change
$is_checked = in_array($term->slug, $selected_terms);
$is_checked = in_array($term->slug, $selected_terms, true);

@@ -0,0 +1,3 @@
{
"plugins": [ "." ]
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not at all opposed to adding this, but it should really be a separate PR.

goldenapples added a commit that referenced this pull request Mar 4, 2026
Originally part of #25, extracted while I'm reworking that PR.
@goldenapples
Copy link

I've rebased this onto the latest main, formatted to fit the rest of the project, and cleaned up any whitespace-only changes in #39. Would appreciate a second review there.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants