Skip to content
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

Missing Query block functionality #24934

Open
1 task done
Tracked by #41405
ntsekouras opened this issue Aug 31, 2020 · 20 comments
Open
1 task done
Tracked by #41405

Missing Query block functionality #24934

ntsekouras opened this issue Aug 31, 2020 · 20 comments
Labels
[Block] Query Loop Affects the Query Loop Block [Feature] Site Editor Related to the overarching Site Editor (formerly "full site editing") [Feature] Themes Questions or issues with incorporating or styling blocks in a theme. [Type] Tracking Issue Tactical breakdown of efforts across the codebase and/or tied to Overview issues.

Comments

@ntsekouras
Copy link
Contributor

ntsekouras commented Aug 31, 2020

With the ongoing work on FSE (#24551) the Milestone:5 is about Query block. The tracking issue for Query block changes/enhancements is here: #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 the REST API can and will be supported from Query 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 the orderby:rand param that has performance issues . An example for needed missing support is order by comments (comment_count): #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

Argument:Option Started Completed
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

Argument:Option Started Completed
orderby:comment_count 🔲 🔲
orderby:menu_order 🔲 🔲

Prioritize

Argument:Option Started Completed
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: #25198

@ntsekouras ntsekouras added [Type] Overview Comprehensive, high level view of an area of focus often with multiple tracking issues [Feature] Full Site Editing [Block] Query Loop Affects the Query Loop Block labels Aug 31, 2020
@kjellr
Copy link
Contributor

kjellr commented Aug 31, 2020

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.

@kjellr kjellr added the [Feature] Themes Questions or issues with incorporating or styling blocks in a theme. label Aug 31, 2020
@ntsekouras
Copy link
Contributor Author

Added order and orderby (title + date) support here: #24691

@TimothyBJacobs
Copy link
Member

Ideally, this would be supporting taxonomies, not categories and tags specifically.

@sc0ttkclark
Copy link

sc0ttkclark commented Sep 16, 2020

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.

@ntsekouras
Copy link
Contributor Author

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.

@noisysocks
Copy link
Member

https://core.trac.wordpress.org/ticket/49983 contained a request for sorting by tags.

@ianstewart
Copy link
Contributor

Not related to the querying itself but useful for pattern/theme creation: #28532

@bobbingwide
Copy link
Contributor

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

@bradhogan
Copy link

Any updates on where post_parent and menu_order are in the updates for the query block?

@danburzo
Copy link

danburzo commented Apr 6, 2022

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.)

@dashkevych
Copy link

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:

  1. Query block that displays featured posts (based on tag)

  2. Query block that displays recent posts (except featured posts)

@sophiegyo
Copy link

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.

@padams
Copy link

padams commented Sep 15, 2022

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.

@sb726
Copy link

sb726 commented Oct 3, 2022

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.

@bradhogan
Copy link

bradhogan commented Oct 24, 2022

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).

@ntsekouras
Copy link
Contributor Author

👋 @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.

@bradhogan
Copy link

@ntsekouras That worked. Thank you!

@sb726
Copy link

sb726 commented Dec 11, 2022

@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

@masteradhoc
Copy link
Contributor

+1 for the exclude functionality of categories, etc.

@annezazu annezazu added [Feature] Site Editor Related to the overarching Site Editor (formerly "full site editing") and removed [Feature] Full Site Editing labels Jul 24, 2023
@supernovia
Copy link

+1 for exclude tags/categories/current post for the single template

@annezazu annezazu added [Type] Tracking Issue Tactical breakdown of efforts across the codebase and/or tied to Overview issues. and removed [Type] Overview Comprehensive, high level view of an area of focus often with multiple tracking issues labels Mar 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Query Loop Affects the Query Loop Block [Feature] Site Editor Related to the overarching Site Editor (formerly "full site editing") [Feature] Themes Questions or issues with incorporating or styling blocks in a theme. [Type] Tracking Issue Tactical breakdown of efforts across the codebase and/or tied to Overview issues.
Projects
None yet
Development

No branches or pull requests