Skip to content

Add block editor block as a Query Loop variation#212

Open
jeherve wants to merge 12 commits into
trunkfrom
add-editor-block
Open

Add block editor block as a Query Loop variation#212
jeherve wants to merge 12 commits into
trunkfrom
add-editor-block

Conversation

@jeherve

@jeherve jeherve commented Feb 27, 2026

Copy link
Copy Markdown
Owner

Summary

  • Adds a block editor block implemented as a Query Loop block variation, allowing users to display posts published "on this day" in previous years directly in the block editor.
  • Custom inspector controls for years back, exact match, group by year, and year heading level.
  • Server-side query filtering via query_loop_block_query_vars and rest_post_query to inject date-based queries.
  • Year heading injection that post-processes core/post-template output to group posts by year with configurable heading levels.
  • Extracts a reusable build_date_query() static method from the Query class for shared use between widget and block.
  • Bumps required WordPress version to 6.8 and plugin version to 2.0.0.
  • Pins all @wordpress/* npm dependencies to exact versions and adds Renovate grouping.

Fixes #7.

Test plan

  • Install the plugin on a WordPress 6.8+ site and verify the "Posts On This Day" block variation appears in the block inserter under the Query Loop category.
  • Add the block to a page and verify the inspector panel shows controls for years back, exact match, group by year, and year heading level.
  • Publish the page and verify posts from previous years on this day are displayed on the front end.
  • Toggle "Group by year" on and verify year headings appear between post groups.
  • Toggle "Exact match" and verify the query narrows to the exact date vs. a week range.
  • Run composer phpunit and verify all 16 tests pass.
  • Run composer phpcs:lint and verify no violations.
  • Run npm run build and verify the JS builds without errors.

@jeherve jeherve self-assigned this Feb 27, 2026
@jeherve jeherve changed the base branch from master to trunk February 27, 2026 09:31
@jeherve jeherve changed the base branch from trunk to master February 27, 2026 09:31
Set up webpack build pipeline via @wordpress/scripts with pinned
dependency versions. Add node_modules/ and build/ to gitignore,
build artifacts to phpcs excludes, and dist excludes.
Add a public static method for building date queries, shared between
the widget and the new block. Uses wp_timezone() for consistent
timezone handling. Add WP_REST_Request stub to test bootstrap and
build_date_query tests to QueryTest.
Test init hook registration, maybe_add_query_filter namespace matching
and idempotency, filter_query_vars with exact/non-exact/empty context,
and filter_rest_query with and without parameters.
Group all @wordpress/* dependencies so they get updated together
in a single PR.
Register the Block class on plugin load. Add changelog entry for the
new block editor integration.
@jeherve jeherve changed the base branch from master to trunk February 27, 2026 09:38
The plugin is no longer just a widget — update the short description,
long description, installation instructions, and tags to reference the
new block editor support alongside the legacy widget.
Set isLink: true on the core/post-title inner block so titles
in the "Posts On This Day" variation are clickable out of the box.
Mention the block alongside the legacy widget, update install
instructions to include npm build step, and replace WorDBless
reference with Brain Monkey.
The block should always query posts, so post type shouldn't be
a user-configurable option in the block settings.
Register query_loop_block_query_vars directly in init() instead of
conditionally via pre_render_block. Inner blocks render before the
parent's pre_render_block fires, so the filter was being added too
late for core/post-template to use it.

Also apply the date filter to the re-query in maybe_inject_year_headings,
since build_query_vars_from_query_block() only extracts core's known
query properties and skips our custom yearsBack/exactMatch attributes.
The core/query block defaults inherit to true, which makes the
post-template use the global WP_Query instead of building a custom one.
On singular pages this means only the page's own post is returned.

Use render_block_data to override inherit to false for our namespace
so our date-based query always runs via query_loop_block_query_vars.
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.

Add block so one can look for and insert old posts as they're writing a new post or page

1 participant