-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Search Block - ability to specify additional search query vars #40585
Search Block - ability to specify additional search query vars #40585
Conversation
Some questions/ideas I have here.
|
Just FYI - opened PR to |
4fc1c52
to
f86c249
Compare
{ !! query && | ||
Object.keys( query ).map( ( key ) => ( | ||
<input | ||
key={ key } | ||
type="hidden" | ||
name={ key } | ||
value={ query[ key ] } | ||
/> | ||
) ) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, @tomasztunik
Sorry if I'm missing something, but what's the reason for outputting hidden
inputs in the editor?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added for consistency in the DOM between the editor/front-end but can be easily removed if we don't see a reason for them to be here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the explanation, @tomasztunik 🙇
The hidden inputs shouldn't affect anything visually; they also serve no purpose in the editor besides consistency. So it's probably safe to remove.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had something ringing the bell but double checked and they are completely ignored in rendering, for CSS selectors etc. Will remove them 👍
In a follow-up PR it could be worth exploring editor controls for this. |
Agreed, in the issue I've shared my findings that there already is query-controls component but as mentioned there:
Having this first would enable us to create variations already and allow more time for the interface to mature at its own pace |
Good point 👍 |
f86c249
to
6d8325a
Compare
It didn't add any value to the editor view. Query attribute is now used only by php to render the block on the frontend
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me 👍 Thanks, @tomasztunik!
Added Needs Dev Note label in case this needs a dev note for 6.1 release. |
What?
Add ability to control search query vars of the core/search block.
Fixes #40583
Why?
This will enable creating core/search block variations that can limit their search results based on query vars provided. Ie. searching only among
post_type=product
for WooCommerce or searching only through a particular category of posts, or a particular author on a WordPress page.How?
Adds
query
attribute to core/search block and renders hidden inputs in the search block with provided query vars and values.Testing Instructions
ie. to search only for pages specify
post_type: 'page'
if WooCommerce is available one could usepost_type: 'product'
- it is possible to use all public query vars and also custom taxonomies where custom taxonomy name slug is query key and value will be a slug representing custom taxonomy entry.Screenshots or screencast