mirror of
https://github.com/WordPress/WordPress.git
synced 2025-01-03 15:08:10 +01:00
Editor: Dynamic site editor template names performance improvements.
This change updates `get_(posts|terms)()` to direct `WP_Query` calls and adds additional parameters to each query to improve performance. Follow-up to [54280], [54333], [54370], and [54388]. Props spacedmonkey, peterwilsoncc. See #56467. Built from https://develop.svn.wordpress.org/trunk@54445 git-svn-id: http://core.svn.wordpress.org/trunk@54004 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
411e2b8580
commit
711c24d3a7
@ -546,13 +546,22 @@ function _build_block_template_result_from_file( $template_file, $template_type
|
||||
function _wp_build_title_and_description_for_single_post_type_block_template( $post_type, $slug, WP_Block_Template $template ) {
|
||||
$post_type_object = get_post_type_object( $post_type );
|
||||
|
||||
$posts = get_posts(
|
||||
array(
|
||||
'name' => $slug,
|
||||
'post_type' => $post_type,
|
||||
)
|
||||
$default_args = array(
|
||||
'post_type' => $post_type,
|
||||
'post_status' => 'publish',
|
||||
'posts_per_page' => 1,
|
||||
'update_post_meta_cache' => false,
|
||||
'update_post_term_cache' => false,
|
||||
'ignore_sticky_posts' => true,
|
||||
'no_found_rows' => true,
|
||||
);
|
||||
|
||||
$args = array(
|
||||
'name' => $slug,
|
||||
);
|
||||
$args = wp_parse_args( $args, $default_args );
|
||||
$posts = new WP_Query( $args );
|
||||
|
||||
if ( empty( $posts ) ) {
|
||||
$template->title = sprintf(
|
||||
/* translators: Custom template title in the Site Editor referencing a post that was not found. 1: Post type singular name, 2: Post type slug. */
|
||||
@ -579,13 +588,12 @@ function _wp_build_title_and_description_for_single_post_type_block_template( $p
|
||||
$post_title
|
||||
);
|
||||
|
||||
$posts_with_same_title = get_posts(
|
||||
array(
|
||||
'title' => $post_title,
|
||||
'post_type' => $post_type,
|
||||
'post_status' => 'publish',
|
||||
)
|
||||
$args = array(
|
||||
'title' => $post_title,
|
||||
);
|
||||
$args = wp_parse_args( $args, $default_args );
|
||||
|
||||
$posts_with_same_title = new WP_Query( $args );
|
||||
|
||||
if ( count( $posts_with_same_title ) > 1 ) {
|
||||
$template->title = sprintf(
|
||||
@ -615,14 +623,21 @@ function _wp_build_title_and_description_for_single_post_type_block_template( $p
|
||||
function _wp_build_title_and_description_for_taxonomy_block_template( $taxonomy, $slug, WP_Block_Template $template ) {
|
||||
$taxonomy_object = get_taxonomy( $taxonomy );
|
||||
|
||||
$terms = get_terms(
|
||||
array(
|
||||
'taxonomy' => $taxonomy,
|
||||
'hide_empty' => false,
|
||||
'slug' => $slug,
|
||||
)
|
||||
$default_args = array(
|
||||
'taxonomy' => $taxonomy,
|
||||
'hide_empty' => false,
|
||||
'update_term_meta_cache' => false,
|
||||
);
|
||||
|
||||
$term_query = new WP_Term_Query();
|
||||
|
||||
$args = array(
|
||||
'number' => 1,
|
||||
'slug' => $slug,
|
||||
);
|
||||
$args = wp_parse_args( $args, $default_args );
|
||||
$terms = $term_query->query( $args );
|
||||
|
||||
if ( empty( $terms ) ) {
|
||||
$template->title = sprintf(
|
||||
/* translators: Custom template title in the Site Editor, referencing a taxonomy term that was not found. 1: Taxonomy singular name, 2: Term slug. */
|
||||
@ -648,13 +663,15 @@ function _wp_build_title_and_description_for_taxonomy_block_template( $taxonomy,
|
||||
$term_title
|
||||
);
|
||||
|
||||
$terms_with_same_title = get_terms(
|
||||
array(
|
||||
'taxonomy' => $taxonomy,
|
||||
'hide_empty' => false,
|
||||
'name' => $term_title,
|
||||
)
|
||||
$term_query = new WP_Term_Query();
|
||||
|
||||
$args = array(
|
||||
'number' => 2,
|
||||
'name' => $term_title,
|
||||
);
|
||||
$args = wp_parse_args( $args, $default_args );
|
||||
|
||||
$terms_with_same_title = $term_query->query( $args );
|
||||
|
||||
if ( count( $terms_with_same_title ) > 1 ) {
|
||||
$template->title = sprintf(
|
||||
|
@ -16,7 +16,7 @@
|
||||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '6.1-beta3-54444';
|
||||
$wp_version = '6.1-beta3-54445';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
Loading…
Reference in New Issue
Block a user