Skip to content

Conversation

@prasadkarmalkar
Copy link
Contributor

What?

Closes #74597

Pre-selects the current term in the Terms List block dropdown when viewing a term archive page.

Why?

Currently, when users select a term from the Terms List block dropdown on archive pages, the page reloads to show posts for that term, but the dropdown resets to the default "Select [taxonomy]" text instead of showing which term is currently active.

How?

Modified block rendering to detect when viewing a term archive page and pre-select the corresponding term in the dropdown.

Testing Instructions

  1. Edit the archive page and add the Term List block
  2. Select the taxonomy and Display as dropdown
  3. Check the term archive page and select different terms

Screenshots or screencast

Screen.Recording.2026-01-14.at.11.31.21.AM.mov

@github-actions github-actions bot added the [Package] Block library /packages/block-library label Jan 14, 2026
@prasadkarmalkar prasadkarmalkar marked this pull request as ready for review January 14, 2026 06:33
@github-actions
Copy link

github-actions bot commented Jan 14, 2026

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Unlinked Accounts

The following contributors have not linked their GitHub and WordPress.org accounts: @davewhitley.

Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Unlinked contributors: davewhitley.

Co-authored-by: prasadkarmalkar <prasadkarmalkar@git.wordpress.org>
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@Mamaduka Mamaduka added [Type] Enhancement A suggestion for improvement. [Block] Categories Affects the Categories Block labels Jan 14, 2026
@Mamaduka
Copy link
Member

Thanks for contributing, @prasadkarmalkar!

The following change works in my tests and matches how the default selected value is set for categories. Though I've not tested this intensively, only with default taxonomies.

diff --git a/packages/block-library/src/categories/index.php b/packages/block-library/src/categories/index.php
index 518918c8a1c..6e742422983 100644
--- a/packages/block-library/src/categories/index.php
+++ b/packages/block-library/src/categories/index.php
@@ -40,6 +40,7 @@ function render_block_core_categories( $attributes, $content, $block ) {
 		$id                       = 'wp-block-categories-' . $block_id;
 		$args['id']               = $id;
 		$args['name']             = $taxonomy->query_var;
+		$args['selected']         = get_query_var( $taxonomy->query_var );
 		$args['value_field']      = 'slug';
 		$args['show_option_none'] = sprintf(
 			/* translators: %s: taxonomy's singular name */

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

Labels

[Block] Categories Affects the Categories Block [Package] Block library /packages/block-library [Type] Enhancement A suggestion for improvement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Terms List block: selected term should be displayed in dropdown select element

2 participants