-
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
Query Loop: Allow custom "Order by" options #40170
Comments
Being able to filter |
Issue #24934 seems to be where this is tracking |
I've had some major struggles with this recently and ending up having to remove the the Query Block completely from my beautiful FSE based project and replace it with a shortcode. The inability to modify or filter the block with complex queries to implement things like meta_query is very problematic and will inevitably lead to rather messy hybrid solutions like mine, which ultimately defeats the entire purpose of FSE. |
@antonyjsmith I can understand folks need more flexibility and we always try to make things better, but all the help we can get is welcome. Some of things are quite complex like the meta_query. Can you share the most important things you were missing and had to remove the block? |
I have a custom field - which happens to be a price - which tbh is a trivial query to build and I cannot order the query by that field [I had to come up with a work around just to display the custom field in the first place but that's another issue]. In reality pretty much anything beyond the most basic sorting options are off the table which creates me a lot of problems. Had menu_order been available I could possibly made do but that's still not implemented either. This being said, I agree meta_query can be quite complicated and think any attempt to implement this via the block editor would be tricky and ultimately likely detrimental to the user experience. However not providing a hook or filter for the query loop feels like a major oversight - I think there is actually a pull request to implement this at the moment but it remains unmerged. The issue here was a rerun of a frequent problem I have with Gutenberg. Run into a limitation > Check documentation [realise there either is none or it doesn't offer any developer details] > Move to Github > Read multiple tickets for hours that have often been open for years > eventually find a ticket related directly to my issue > discover there is no workaround or there's an unmerged pull > solve the issue using previous method [in this case shortcode] in a fraction of time than it took to realise the functionality doesn't exist. The open issues on the Github repo is somewhat of a dumpster fire and tbh I've spent more time than I care to add up trawling through on futile workaround hunts. I get that implementing features using the new paradigm takes a ton of time and effort but just leaving them out and not adding filters or hooks for developers is a major oversight. |
There is now a filter for the query vars ( Unfortunately it doesn't solve the original problem, but it's been helpful for other Query Loop modifications, so I wanted to mention it on this thread. |
It looks like version 6.1 has some functionality that might help: https://make.wordpress.org/core/2022/10/10/extending-the-query-loop-block/ & https://developer.wordpress.org/block-editor/how-to-guides/block-tutorial/extending-the-query-loop-block/ |
There is a good article about how to make the Query Loop block orderby a custom field (meta_key) at the link below. Currently it requires:
NOTE: the code in the following article has an error. Change $query['orderby'] = 'meta_key'; to $query['orderby'] = 'meta_value'; https://wpfieldwork.com/modify-query-loop-block-to-filter-by-custom-field/#loop-modifications |
I’m trying to apply changes to the query for a query loop block, inspired by the |
I have a Query Loop using a custom post type (Sessions), and I want to order them by session date (not publish date). Session date is a meta value, though I've added a custom handling for
orderby=session_date
in the API — but I can't select this option in the default Query Loop settings, and I can't change the settings to add it (see WordPress/wordcamp.org#754 for my initial attempt at this).A possible idea for this could be to allow filtering of the
orderOptions
here. Then plugin devs could add custom options, like{ label: 'Earliest first', value: 'session_date/asc' }
, trusting that the API will handle the orderby correctly.The text was updated successfully, but these errors were encountered: