Skip to content

Add filter to flat term selector#58941

Closed
mauteri wants to merge 5 commits intoWordPress:trunkfrom
mauteri:improve/flat-term-selector-query-filter
Closed

Add filter to flat term selector#58941
mauteri wants to merge 5 commits intoWordPress:trunkfrom
mauteri:improve/flat-term-selector-query-filter

Conversation

@mauteri
Copy link
Copy Markdown
Contributor

@mauteri mauteri commented Feb 12, 2024

What?

This is a follow up to a PR I submitted that was merged. This PR adds a filter to the query for those that want more control over the query.

Why?

There was a comment left on my PR asking for the older behavior. In some situations when there is a lot of terms, the query is not ideal. Having control over this in a case by case basis can be handy.

How?

This just applies a filter named editor.FlatTermSelector.queryArgs to the query. It passes the DEFAULT_QUERY constant as default query, and taxonomy slug as second argument.

Testing Instructions

  1. Normal behavior should be retained when code is not leveraging filter.
  2. Add hook to filter to manipulate query.
  3. Optionally use taxonomy in conditional.

Testing Instructions for Keyboard

N/A

Screenshots or screencast

N/A

@github-actions
Copy link
Copy Markdown

github-actions bot commented Feb 12, 2024

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.

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

Co-authored-by: mauteri <mauteri@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.

@skorasaurus skorasaurus added the [Feature] Document Settings Document settings experience label Feb 22, 2024
@github-actions
Copy link
Copy Markdown

Warning: Type of PR label mismatch

To merge this PR, it requires exactly 1 label indicating the type of PR. Other labels are optional and not being checked here.

  • Type-related labels to choose from: [Type] Automated Testing, [Type] Breaking Change, [Type] Bug, [Type] Build Tooling, [Type] Code Quality, [Type] Copy, [Type] Developer Documentation, [Type] Enhancement, [Type] Experimental, [Type] Feature, [Type] New API, [Type] Task, [Type] Technical Prototype, [Type] Performance, [Type] Project Management, [Type] Regression, [Type] Security, [Type] WP Core Ticket, Backport from WordPress Core.
  • Labels found: [Feature] Document Settings.

Read more about Type labels in Gutenberg. Don't worry if you don't have the required permissions to add labels; the PR reviewer should be able to help with the task.

@mauteri
Copy link
Copy Markdown
Contributor Author

mauteri commented Mar 11, 2024

Hi, I just wanted to follow up on this PR as I put it in some time ago. Is there any feedback or could this code be approved and merged as is? Thanks!

@Mamaduka
Copy link
Copy Markdown
Member

Mamaduka commented Jun 6, 2024

@mauteri,

Considering that the search query can be modified via the HTTP API filter, I am unsure how helpful the new filter would be.

Additionally, whole-term selector components can be replaced via the editor.PostTaxonomyType filter, which provides more flexibility.

Example filter

add_filter( 'rest_post_tag_query', function( $query_args, $request ) {
	// Only modify search query.
	if ( ! isset( $query_args['search'] ) ) {
		return $query_args;
	}

	// Display most used tags first.
	$query_args['order']   = 'desc';
	$query_args['orderby'] = 'count';

	return $query_args;
}, 10, 2 );

@mauteri
Copy link
Copy Markdown
Contributor Author

mauteri commented Jun 6, 2024

That makes sense. I'll close this PR. Thx!

@mauteri mauteri closed this Jun 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Feature] Document Settings Document settings experience

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants