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

Adding more filters to query block #31390

Closed
MocioF opened this issue Apr 30, 2021 · 9 comments
Closed

Adding more filters to query block #31390

MocioF opened this issue Apr 30, 2021 · 9 comments
Labels
[Block] Query Loop Affects the Query Loop Block [Type] Enhancement A suggestion for improvement.

Comments

@MocioF
Copy link

MocioF commented Apr 30, 2021

I am trying to use the query block, and I think it could be useful to find a way to filter the query by more fields.
I.e. I am trying to filter page-type posts, and I'd like to chose which to show, by a custom filter.
I have seen a page builder has an option in filtering, passing a custom string that is a filter name created in the theme.
In this way, posts can be filtered by custom fields too.

@paaljoachim paaljoachim added [Block] Query Loop Affects the Query Loop Block [Type] Enhancement A suggestion for improvement. labels Apr 30, 2021
@wwdes
Copy link

wwdes commented May 13, 2021

I can think of two things that in my opinion should be possible to do with Query Blocks.

#1 Ability to select multiple specific posts to make a list of posts that is not based on post type or categories. Maybe have an "Custom list" option in the "Post type" dropdown of Query Block settings pane. And after selecting it the author can then add any posts to the list either by searching or specifying title/slug/id.

#2 Ability to use a custom query which will be defined outside of editor where one could code any query desired. One solution that I have seen for this is by using action hooks. For example, lets say we want to get all posts that have a featured image. This is how it could look like:

add_action( 'gutenberg/query/thumbnail_only', 'my_gutenberg_query_thumbnail_only' );
function my_gutenberg_query_thumbnail_only( $query ) {
	$meta_query = array(array(
		'key' => '_thumbnail_id',
		'compare' => 'EXISTS'
	));
	$query->set( 'meta_query', $meta_query );
}

Then, in the settings pane of a Query Block we could specify our custom query name which in this case would be thumbnail_only.

EDIT:
#3 An option to limit post count to any number.

@dashkevych
Copy link

It would be great to have a way to select specific pages (CPT=Page) to display in this block.

@mrfoxtalbot
Copy link

It would be very helpful to include:

  • Support to select specific posts, pages or CPTs (similar to the way "Keywords" currently works, but displaying a dropdown showing which posts include that word)
  • Query child pages (or any other hierarchical CPT) by selecting the parent page.

@antonyjsmith
Copy link

The lack of ability to filter by more specific criteria really limits the usefulness of this block.

@skorasaurus
Copy link
Member

Several of these features mentioned in here have been implemented:

  • filtering by keyword
  • limiting the post count (done by selecting the number of pages to load in the query toolbar along with choosing the number of pages to display per page)

@ersatzpenguin
Copy link

In addition to @mrfoxtalbot's suggestion for filtering "child of x" pages, it'd be really cool if we could query top level pages. I'm working on a project where we're creating a knowledge-base, and being able to have robust page hierarchy options would make it a lot easier to drill down topics using static pages. As it is, I'm having to build things out as posts instead—which isn't that big of a deal, but it wasn't our first choice.

@skorasaurus
Copy link
Member

In addition to @mrfoxtalbot's suggestion for filtering "child of x" pages, it'd be really cool if we could query top level pages. I'm working on a project where we're creating a knowledge-base, and being able to have robust page hierarchy options would make it a lot easier to drill down topics using static pages. As it is, I'm having to build things out as posts instead—which isn't that big of a deal, but it wasn't our first choice.

There's a Pull request for this feature - #40933 ; you can try it (on a local/testing website, because there may be small bugs!) by downloading the zip at the directions at #40483 (comment)

@ntsekouras
Copy link
Contributor

👋 - after reading the extending Query Loop docs, do you think we can close this issue? If not can you pinpoint the specifics that are needed and check if there are existing issues or update this one? Thanks!

@MocioF
Copy link
Author

MocioF commented Mar 10, 2023

Now the Query loop block can be customized and extended

@MocioF MocioF closed this as completed Mar 10, 2023
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 [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

No branches or pull requests

9 participants