Skip to content

Filter custom block templates with PHP#2031

Closed
Mamaduka wants to merge 1 commit intoWordPress:trunkfrom
Mamaduka:core/2020-block-template-follow-up
Closed

Filter custom block templates with PHP#2031
Mamaduka wants to merge 1 commit intoWordPress:trunkfrom
Mamaduka:core/2020-block-template-follow-up

Conversation

@Mamaduka
Copy link
Copy Markdown
Member

@Mamaduka Mamaduka commented Dec 8, 2021

Follow-up for #2020.

This method calls get_block_templates once and uses block template properties directly for filtering. This way, we can avoid hitting the database for each public post type.

The previous method is useful when we already know the current post type we request templates for, like when using REST API.

Trac ticket: https://core.trac.wordpress.org/ticket/54335


Cc @youknowriad @noisysocks @hellofromtonya

foreach ( get_post_types( array( 'public' => true ) ) as $type ) {
$block_templates = get_block_templates( array( 'post_type' => $type ), 'wp_template' );
foreach ( $block_templates as $block_template ) {
if ( ! $block_template->is_custom ) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel maybe this should be internal to get_block_templates (an argument of the query) but I'm fine with this approach as well.

@noisysocks
Copy link
Copy Markdown
Member

@noisysocks noisysocks closed this Dec 14, 2021
@Mamaduka Mamaduka deleted the core/2020-block-template-follow-up branch April 7, 2022 10:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants