Add Posts and Replies block using query_loop_block_query_vars#3036
Open
Add Posts and Replies block using query_loop_block_query_vars#3036
Conversation
Alternative approach to #1213: instead of running custom queries, this block renders a tab bar that controls a sibling core/query block via the `query_loop_block_query_vars` filter. The "Posts" tab (default) filters out posts containing the `activitypub/reply` block. The "Posts & Replies" tab shows all posts. Tab state is managed via a URL parameter (`?ap_tab=`), so pagination and the Query Loop block work naturally without custom query logic. This preserves full core/query customization in the Site Editor. Related: #1213
- Replace ARIA role="tab" with nav + aria-current="page" since tabs are navigation links (page reloads), not JS-controlled panels. - Reset pagination when switching tabs to avoid out-of-range pages. - Use focus-visible instead of focus for cleaner keyboard indication.
There was a problem hiding this comment.
Pull request overview
Adds a new “Posts and Replies” block intended for author archive templates that provides a tab UI and filters the adjacent Query Loop via query_loop_block_query_vars, avoiding a custom WP_Query so users retain full Site Editor control over layout.
Changes:
- Introduces
activitypub/posts-and-repliesblock (editor placeholder + server-rendered tab bar + styles). - Hooks
query_loop_block_query_varsto conditionally exclude “reply” posts by adding aposts_whereclause. - Updates the plugin’s Fediverse author archive template to include the new block above the Query Loop.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| src/posts-and-replies/block.json | Defines new dynamic block metadata. |
| src/posts-and-replies/index.js | Registers the block (dynamic render, editor-only UI). |
| src/posts-and-replies/edit.js | Editor placeholder/instructions for template placement. |
| src/posts-and-replies/render.php | Server-rendered tab bar driven by ?ap_tab=.... |
| src/posts-and-replies/style.scss | Frontend styles for the tab bar. |
| includes/class-blocks.php | Registers the block/template and adds Query Loop filtering + SQL where clause. |
| build/posts-and-replies/block.json | Generated build artifact for block metadata. |
| build/posts-and-replies/index.js | Generated build artifact for editor script bundle. |
| build/posts-and-replies/index.asset.php | Generated build artifact for script dependencies/version. |
| build/posts-and-replies/render.php | Generated build artifact for server render. |
| build/posts-and-replies/style-index.css | Generated build artifact for styles. |
| build/posts-and-replies/style-index-rtl.css | Generated build artifact for RTL styles. |
You can also share your feedback on Copilot code review. Take the survey.
query_loop_block_query_vars never fires when the Query Loop uses inherit:true — it clones the global WP_Query directly, skipping build_query_vars_from_query_block() entirely. Switch to pre_get_posts on the main query so the reply exclusion filter applies to inherited queries on author archives.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related: #1213
Alternative to #3035 — uses a different architecture.
Proposed changes:
activitypub/posts-and-repliesblock that renders a tab bar on any page (hidden from ActivityPub requests and feeds).core/queryblock via thequery_loop_block_query_varsfilter.posts_whereclause to exclude posts containing theactivitypub/replyblock. The "Posts & Replies" tab shows all posts unfiltered.?filter=posts-and-replies), so pagination and Query Loop work naturally.core/queryis preserved as-is.Comparison with #3035
WP_Queryin render.phpcore/queryviaquery_loop_block_query_varsOther information:
Testing instructions:
npm run env-start.Posts and Repliesblock appears above the Query Loop block./author/admin/).activitypub/replyblock (Federated Reply).?filter=posts-and-repliesand the reply post appears.Changelog entry
Changelog Entry Details
Significance
Type
Message
Add a "Posts and Replies" tab bar that filters between posts and replies, similar to Mastodon's profile view.