Skip to content

Conversation

@Arukuen
Copy link
Contributor

@Arukuen Arukuen commented Jan 25, 2026

fixes #3678

This is not a bug but a feature request. The selected taxonomy under Filter by Taxonomy is used for filtering which post items are displayed. To be able to display custom taxonomy terms instead of Categories, we have to add that option.

Summary by CodeRabbit

  • New Features
    • Added configurable taxonomy display option to the Posts block. Users can now select which taxonomy type (e.g., categories, tags, or custom taxonomies) to display alongside each post. The block defaults to categories but now supports any available taxonomy, providing greater flexibility in content presentation.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Jan 25, 2026

📝 Walkthrough

Walkthrough

The changes introduce support for displaying custom taxonomies in the Posts block instead of hardcoded categories. A new taxonomyTypeToDisplay attribute is added throughout the stack, with UI controls to select which taxonomy to display, and backend logic now retrieves and renders terms from the selected taxonomy dynamically.

Changes

Cohort / File(s) Summary
Frontend Editor Configuration
src/block/posts/edit.js, src/block/posts/schema.js, src/components/taxonomy-control/index.js
Added taxonomyTypeToDisplay attribute definition (default: 'category') and integrated prop plumbing through Edit component. New UI control "Taxonomy to Display" in TaxonomyControl renders when taxonomy options exist, with automatic synchronization when Post Type changes.
Backend Taxonomy Retrieval
src/block/posts/index.php
Replaced hardcoded category retrieval with get_taxonomy_term_list_by_id() method supporting any taxonomy. Added taxonomy-aware rendering logic to fetch and display terms based on taxonomyTypeToDisplay attribute instead of categories only.
Query Hook Integration
src/hooks/use-posts-query.js
Extended usePostsQuery to destructure taxonomyTypeToDisplay from attributes and include it as taxonomy_type_to_display in the API request payload, with dependency array updates.

Sequence Diagram

sequenceDiagram
    participant Editor as Editor (edit.js)
    participant UI as TaxonomyControl
    participant Attr as Block Attributes
    participant Hook as usePostsQuery Hook
    participant API as Backend (index.php)
    participant Frontend as Frontend Render

    Editor->>Attr: User selects taxonomy type
    Attr->>UI: taxonomyTypeToDisplay updated
    UI->>Attr: onChangeTaxonomyTypeToDisplay triggered
    Attr->>Hook: taxonomyTypeToDisplay in attributes
    Hook->>API: POST request with taxonomy_type_to_display
    API->>API: get_taxonomy_term_list_by_id(post_id, taxonomy)
    API->>Frontend: Return posts with selected taxonomy terms
    Frontend->>Frontend: Render taxonomy terms instead of categories
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes


🐰 A taxonomy of posts, so grand and bright,
Now custom terms dance into the light!
From ACF fields to frontend display,
The block learns new taxonomies today!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title accurately describes the main feature: adding an option to change which taxonomy is displayed, moving beyond the hardcoded category display.
Linked Issues check ✅ Passed The PR implements the core requirement from issue #3678: enabling the Posts Block to display custom taxonomy terms instead of only categories when a custom taxonomy is used.
Out of Scope Changes check ✅ Passed All changes are directly scoped to the objective of adding taxonomy selection functionality; no unrelated modifications detected across the five modified files.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link

🤖 Pull request artifacts

file commit
pr3679-stackable-3679-merge.zip 12fc19e

github-actions bot added a commit that referenced this pull request Jan 25, 2026
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/components/taxonomy-control/index.js (1)

148-153: Add safe defaults for the new taxonomyTypeToDisplay props to avoid breaking deprecated code.

The deprecated v2/block/blog-posts block does not pass the new taxonomyTypeToDisplay and onChangeTaxonomyTypeToDisplay props. When this block's Post Type changes (line 152), the undefined handler throws an error. Additionally, the new "Taxonomy to Display" control (lines 202, 205) calls undefined. Add these props to defaultProps for backward compatibility.

Proposed fix (defaultProps)
 TaxonomyControl.defaultProps = {
 	postType: 'post',
 	onChangePostType: () => {},
 	taxonomyType: 'category',
 	onChangeTaxonomyType: () => {},
 	taxonomy: '',
 	onChangeTaxonomy: () => {},
 	allowReset: false,
+	taxonomyTypeToDisplay: 'category',
+	onChangeTaxonomyTypeToDisplay: () => {},
 }

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.

Posts Block - does not display taxonomy terms for CPT when using ACF registered taxonomies

2 participants