-
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
Add a filter hook to post template WP_Query or build_query_vars_from_query_block() #36504
Comments
This would also solve that is currently it is not possible to extend the Post Template block to add support for custom taxonomies. Adding the ability to filter the query args and access the attributes would allow anyone to extend the query however they need. |
I have created a trac ticket and have added a patch https://core.trac.wordpress.org/ticket/54850 |
As I have started to try and use the new filter, I have realized that attributes from the |
This would also be helpful for me as I was just looking to extend the functionality of the Query Loop block and found it completely lacking in this particular area for me and other developers to customize the query arguments that the function builds up using the WP_Block object context information. I went through and was about to create a PR until I thought to double check and see if someone had already submitted one. The patch/PR in WordPress/wordpress-develop#2185 does exactly what I'd want to be able to do here which is filter the query arguments based on the block object itself and any context passed to it. |
Shouldn't this be changed in Gutenberg repository (too)? gutenberg/lib/compat/wordpress-6.0/blocks.php Line 126 in de11d1d
|
Thanks for the issue @msaari! I'm closing this as this has been implemented here: #43590. You can read more about extending Query Loop in the related docs page. Feel free to reopen, if you need something more/different. |
The Relevanssi search plugin does not work with Query Loop and Post Template blocks. When there's a search results page built using the Query Loop and Post Template blocks, the results come up empty when Relevanssi is active. This is because Relevanssi cannot override the WP_Query used in the Post Template block.
This would be easy to fix by adding a single filter hook somewhere in the process. All Relevanssi needs is the ability to add a
relevanssi
query variable, set totrue
.This could be done either in the Post Template block by changing
$query = new WP_Query( $query_args );
in
build/block-library/blocks/post-template.php
to$query = new WP_Query( apply_filters( 'gutenberg_render_block_core_post_template_query_args', $query_args ) );
or in the
build_query_vars_from_query_block()
function inwp-includes/block.php
by changingreturn $query;
to
return apply_filters( 'query_vars_from_query_block', $query );
Either way, this would let Relevanssi get in the query and the search would work. There would be no adverse side effects, and I'm sure Relevanssi isn't the only party with an interest in getting to touch the query variables in these processes.
The text was updated successfully, but these errors were encountered: