[wp-trac] [WordPress Trac] #62014: Editor: Add a 'format' parameter to query to enable filtering post formats in the Query Loop block
WordPress Trac
noreply at wordpress.org
Wed Sep 11 06:12:20 UTC 2024
#62014: Editor: Add a 'format' parameter to query to enable filtering post formats
in the Query Loop block
-------------------------------------------------+-------------------------
Reporter: poena | Owner: (none)
Type: enhancement | Status: new
Priority: normal | Milestone: 6.7
Component: Editor | Version:
Severity: normal | Resolution:
Keywords: has-patch has-testing-info needs- | Focuses:
testing |
-------------------------------------------------+-------------------------
Changes (by poena):
* keywords: has-patch => has-patch has-testing-info needs-testing
Old description:
> I am opening this ticket tentatively to add the PHP changes from this
> Gutenberg PR:
> [https://github.com/WordPress/gutenberg/pull/64167 Query loop / Post
> template: Enable post format filter]
>
> At the time of opening this issue, this linked PR has not yet been
> approved, and this ticket should not be committed.
> I expect that there will be some additional changes to the PR.
>
> I could use help with adding a better summary (ticket title) and clearer
> description, but I will try my best.
>
> The Gutenberg PR linked above adds a new filter to the Query Loop block,
> that the user can use to display posts (or other post types) that have
> post formats assigned.
>
> The PR adds a new parameter called 'format' to the class
> {{{WP_REST_Posts_Controller}}}. Changes are made to these class methods:
> get_item and get_collection_params.
>
> 'Format' is also added to the function
> {{{build_query_vars_from_query_block}}}, which is used to display the
> correct posts on the front.
>
> ----
>
> == Testing instructions
>
> How to test the post formats filter without the rest of the Gutenberg
> changes.
>
> First, please enable post formats on the active theme. Example:
> {{{
> function twentytwentyfour_post_formats() {
> add_theme_support( 'post-formats', array( 'aside', 'gallery',
> 'link', 'image', 'quote', 'status', 'video', 'audio', 'chat' ) );
> }
> add_action( 'after_setup_theme', 'twentytwentyfour_post_formats' );
> }}}
>
> On your WordPress test install, create a few posts with and without
> formats assigned.
>
> In the Site Editor or block editor, insert a query loop with a format
> filter.
> In this example, I have used the gallery post format. I have added
> {{{"format":["gallery"]}}} inside {{{query}}}:
>
> {{{
> <!-- wp:query
> {"query":{"perPage":10,"pages":0,"offset":0,"postType":"post","order":"desc","orderBy":"date","author":"","search":"","exclude":[],"sticky":"","inherit":true,"format":["gallery"]}}
> -->
> <div class="wp-block-query">
> <!-- wp:post-template -->
> <!-- wp:post-title /-->
> <!-- /wp:post-template -->
> </div>
> <!-- /wp:query -->
> }}}
>
> In the editor and front, the query loop should only display posts with
> the gallery post format.
>
> Next, change the format to standard:
>
> {{{
> <!-- wp:query
> {"query":{"perPage":10,"pages":0,"offset":0,"postType":"post","order":"desc","orderBy":"date","author":"","search":"","exclude":[],"sticky":"","inherit":true,"format":["standard"]}}
> -->
> <div class="wp-block-query">
> <!-- wp:post-template -->
> <!-- wp:post-title /-->
> <!-- /wp:post-template -->
> </div>
> <!-- /wp:query -->
> }}}
>
> In the editor and front, the query loop should only display posts that
> have no post format assigned.
New description:
I am opening this ticket tentatively to add the PHP changes from this
Gutenberg PR:
[https://github.com/WordPress/gutenberg/pull/64167 Query loop / Post
template: Enable post format filter]
At the time of opening this issue, this linked PR has not yet been
approved, and this ticket should not be committed.
I expect that there will be some additional changes to the PR.
I could use help with adding a better summary (ticket title) and clearer
description, but I will try my best.
The Gutenberg PR linked above adds a new filter to the Query Loop block,
that the user can use to display posts (or other post types) that have
post formats assigned.
The PR adds a new parameter called 'format' to the class
{{{WP_REST_Posts_Controller}}}. Changes are made to these class methods:
get_item and get_collection_params.
'Format' is also added to the function
{{{build_query_vars_from_query_block}}}, which is used to display the
correct posts on the front.
----
== Testing instructions
How to test the post formats filter without the rest of the Gutenberg
changes.
First, please enable post formats on the active theme. Example:
{{{
function twentytwentyfour_post_formats() {
add_theme_support( 'post-formats', array( 'aside', 'gallery',
'link', 'image', 'quote', 'status', 'video', 'audio', 'chat' ) );
}
add_action( 'after_setup_theme', 'twentytwentyfour_post_formats' );
}}}
On your WordPress test install, create a few posts with and without
formats assigned.
In the Site Editor or block editor, insert a query loop with a format
filter.
Since the control itself is not included in the PR, you will need to open
the code editor mode in the editor and manually add the format.
In this example, I have used the gallery post format. I have added
{{{"format":["gallery"]}}} inside {{{query}}}:
{{{
<!-- wp:query
{"query":{"perPage":10,"pages":0,"offset":0,"postType":"post","order":"desc","orderBy":"date","author":"","search":"","exclude":[],"sticky":"","inherit":true,"format":["gallery"]}}
-->
<div class="wp-block-query">
<!-- wp:post-template -->
<!-- wp:post-title /-->
<!-- /wp:post-template -->
</div>
<!-- /wp:query -->
}}}
In the editor and front, the query loop should only display posts with the
gallery post format.
Next, change the format to standard:
{{{
<!-- wp:query
{"query":{"perPage":10,"pages":0,"offset":0,"postType":"post","order":"desc","orderBy":"date","author":"","search":"","exclude":[],"sticky":"","inherit":true,"format":["standard"]}}
-->
<div class="wp-block-query">
<!-- wp:post-template -->
<!-- wp:post-title /-->
<!-- /wp:post-template -->
</div>
<!-- /wp:query -->
}}}
In the editor and front, the query loop should only display posts that
have no post format assigned.
--
--
Ticket URL: <https://core.trac.wordpress.org/ticket/62014#comment:5>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list