Open ntsekouras opened 4 years ago
I think we should definitely prioritize tags
first. Then we'll have both category + tags working correctly. It's really common for themes to utilize a "featured" tag to posts to display them on the homepage. Once something like that is working for block-based themes, that'll be a big plus.
I think search
is necessary to get a search results page template working, so that seems like a good second priority from my perspective.
Added order
and orderby
(title + date) support here: https://github.com/WordPress/gutenberg/pull/24691
Ideally, this would be supporting taxonomies, not categories and tags specifically.
Is there any possible way for a plugin to extend the query block for it's own purposes? For instance, a custom fields plugin that would like to add custom field filtering functionality or advanced filtering options. Does that solution have to extend the query block JS itself and then build out the Edit/Inspector Panel interface on the plugin dev's side?
Asking because I think we might see this happen quite a bit for this block.
Hey @sc0ttkclark !
Is there any possible way for a plugin to extend the query block for it's own purposes? For instance, a custom fields plugin that would like to add custom field filtering functionality or advanced filtering options. Does that solution have to extend the query block JS itself and then build out the Edit/Inspector Panel interface on the plugin dev's side?
The query block could be extended like any other block with filters API: https://developer.wordpress.org/block-editor/developers/filters/block-filters/. Any extension though should be supported by the REST API.
Since there are definitely some things missing and more will be found that are needed, REST API should also be changed to support more things.
https://core.trac.wordpress.org/ticket/49983 contained a request for sorting by tags.
Not related to the querying itself but useful for pattern/theme creation: https://github.com/WordPress/gutenberg/issues/28532
Some more requirements to add to the list.
Argument | Use case |
---|---|
post_type | Ability to select multiple post types |
post_type | Ability to select attachments |
post_type | Ability to select post types which aren't supported by the REST API |
meta_key & meta_value | Ability to use meta key and meta value to limit results |
customcategoryname | Ability to select custom taxonomy terms |
post_parent | Ability to select post parent ( see #31063 ) |
post_mime_type | Ability to select post_mime_type. e.g. PDF attachments |
post_status | Ability to select post_status e.g. schedule |
include / exclude | Ability to select posts to include / exclude |
IDs | Ability to select specific post IDs - so that they can be formatted by query-posts |
Any updates on where post_parent and menu_order are in the updates for the query block?
Any updates on where post_parent and menu_order are in the updates for the query block?
These are exactly the two options that I currently miss the most. Note that switching to the code editor and adding menu_order
manually as the sorting works (at least in WP 5.9.3). (Not so for post_parent
.)
I think we should definitely prioritize
tags
first. Then we'll have both category + tags working correctly. It's really common for themes to utilize a "featured" tag to posts to display them on the homepage. Once something like that is working for block-based themes, that'll be a big plus.I think
search
is necessary to get a search results page template working, so that seems like a good second priority from my perspective.
I agree that having a tag filter would be very useful for highlighting special posts on a page (functionality that is similar that Jetpack has for Featured Content).
However, it would be also very useful to have a functionality in Query block to exclude posts by tag to avoid duplicates.
For instance, the page has two Query blocks:
Query block that displays featured posts (based on tag)
Query block that displays recent posts (except featured posts)
I agree that having a tag filter would be very useful for highlighting special posts on a page (functionality that is similar that Jetpack has for Featured Content).
I was going to add the exact same thing; it'd be very nifty to have a method of excluding a taxonomy from a query loop, to have a few 'featured' posts at the top of a template, that are then not repeated in the query loop below.
One additional display option that would simplify a lot of code and pattens would be to have the block show the posts' featured image and title or just the featured image. In the case of attachment post type - the attachment's image.
Coming from #44041 I would just like to add a vote for custom taxonomy terms (tax_relation??) in the Query Loop. Just to be clear, it is really useful to be able to inherit the Query Loop (for say an index page or category page) AND filter that page according to a custom taxonomy. This was possible (as a bug it seems) in version 6.01. It disappeared in 6.02. I'm hoping we get the functionality back perhaps through this workflow. It means you can do a great deal with category pages.
Happy to open a new ticket if necessary. Seems that you cannot create a template for a custom taxonomy then use the query block on that template to display the custom posts that are associated with that tax.
So..
If I have registered let's say Books (cpt) and Genre (custom tax).
I then create a taxonomy-genre.html template with a query:
<!-- wp:query {"queryId":0,"query":{"perPage":12,"pages":100,"offset":0,"postType":"books","order":"desc","orderBy":"date","author":"","search":"","exclude":[],"sticky":"","inherit":false,"parents":[]},"displayLayout":{"type":"flex","columns":3},"align":"full"} -->
<div class="wp-block-query alignfull">
<!-- wp:post-template -->
<!-- wp:post-featured-image {"isLink":true} /-->
<!-- wp:post-title {"isLink":true,"style":{"spacing":{"margin":{"top":"var:preset|spacing|50","bottom":"var:preset|spacing|20"}}},"fontSize":"large"} /-->
<!-- wp:group {"className":"taxonomy-as-buttons","layout":{"type":"flex","flexWrap":"wrap"}} -->
<div class="wp-block-group taxonomy-as-buttons">
<!-- wp:post-terms {"term":"genre","separator":""} /-->
<!-- wp:post-terms {"term":"series","separator":""} /-->
</div>
<!-- /wp:group -->
<!-- wp:post-excerpt {"moreText":"","style":{"spacing":{"margin":{"top":"var:preset|spacing|40"}}},"fontSize":"small"} /-->
<!-- /wp:post-template -->
<!-- wp:query-no-results --><!-- wp:paragraph {"placeholder":"Add text or blocks that will display when a query returns no results."} --><p>Sorry, no books.</p><!-- /wp:paragraph --><!-- /wp:query-no-results -->
</div>
<!-- /wp:query -->
Then in the front-end, I click a genre link (let's say "Mystery" as an example), I'm seeing ALL books (the query is not limited the results to just the cpt and custom tax).
👋 @bradley2083 I noticed in your Query Block that you have:
"inherit":false
When you want to use the block in a template you should have the block to inherit from the global query, so it should be true
. Please share if you still have issues with the suggested change.
@ntsekouras That worked. Thank you!
@TimothyBJacobs
Could I merge this issue #44041 (which seems to be related), i.e. incorporating full taxonomies into the query block so that filtering is possible across categories and other terms while the query is being inherited from the main search
+1 for the exclude functionality of categories, etc.
+1 for exclude tags/categories/current post for the single template
With the ongoing work on FSE (https://github.com/WordPress/gutenberg/issues/24551) the Milestone:5 is about
Query
block. The tracking issue forQuery
block changes/enhancements is here: https://github.com/WordPress/gutenberg/issues/24762.This issue will be an overview for identifying and adding more options/parameters in
Query
block.The goal is to identify which parameters from
WP_Query
and theREST API
can and will be supported fromQuery
block.There will be definitely some work in
REST API
to support some missing parameters and options if it makes sense and there are no blockers, like theorderby:rand
param that has performance issues . An example for needed missing support isorder by
comments (comment_count
): https://github.com/WordPress/gutenberg/issues/22002.The below list is just the starting point for identifying the parameters to be supported and it will be finalised after discussions with everyone in the community about what parameters should eventually be supported. For now it contains items that are supported and/or make sense to me to be included. Feel free to share your thoughts and add/edit things to make this complete.
WP_Query reference: https://developer.wordpress.org/reference/classes/wp_query/ Posts API reference: https://developer.wordpress.org/rest-api/reference/posts/#list-posts
Supported from REST API
page
per_page
offset
categories
post_type
order
orderby:title
orderby:date
orderby:author
orderby:parent
orderby:modified
tags_exclude
categories_exclude
before
after
author
author_exclude
sticky
tax_relation
include
exclude
NOT Supported from REST API
orderby:comment_count
orderby:menu_order
Prioritize
tags
search
Display options
We should also provide some different display options for the Query block itself and possible children Post blocks like
PostTitle
,PostExcerpt
etc. to enable users to create a list of entities which is highly customizable. This would also allow us to have more block variations and patterns.Query block design
Issue about the design is here: https://github.com/WordPress/gutenberg/issues/25198