diff --git a/src/wp-includes/general-template.php b/src/wp-includes/general-template.php index e42ccc9505..e19b6244b7 100644 --- a/src/wp-includes/general-template.php +++ b/src/wp-includes/general-template.php @@ -579,7 +579,10 @@ function wp_title($sep = '»', $display = true, $seplocation = '') { // If there's a post type archive if ( is_post_type_archive() ) { - $post_type_object = get_post_type_object( get_query_var( 'post_type' ) ); + $post_type = get_query_var( 'post_type' ); + if ( is_array( $post_type ) ) + $post_type = reset( $post_type ); + $post_type_object = get_post_type_object( $post_type ); if ( ! $post_type_object->has_archive ) $title = post_type_archive_title( '', false ); } @@ -706,7 +709,11 @@ function post_type_archive_title( $prefix = '', $display = true ) { if ( ! is_post_type_archive() ) return; - $post_type_obj = get_post_type_object( get_query_var( 'post_type' ) ); + $post_type = get_query_var( 'post_type' ); + if ( is_array( $post_type ) ) + $post_type = reset( $post_type ); + + $post_type_obj = get_post_type_object( $post_type ); $title = apply_filters('post_type_archive_title', $post_type_obj->labels->name ); if ( $display ) @@ -1689,7 +1696,11 @@ function feed_links_extra( $args = array() ) { $href = get_post_comments_feed_link( $post->ID ); } } elseif ( is_post_type_archive() ) { - $post_type_obj = get_post_type_object( get_query_var( 'post_type' ) ); + $post_type = get_query_var( 'post_type' ); + if ( is_array( $post_type ) ) + $post_type = reset( $post_type ); + + $post_type_obj = get_post_type_object( $post_type ); $title = sprintf( $args['posttypetitle'], get_bloginfo( 'name' ), $args['separator'], $post_type_obj->labels->name ); $href = get_post_type_archive_feed_link( $post_type_obj->name ); } elseif ( is_category() ) { diff --git a/src/wp-includes/post.php b/src/wp-includes/post.php index e088c2b449..ddd73bc737 100644 --- a/src/wp-includes/post.php +++ b/src/wp-includes/post.php @@ -1058,9 +1058,6 @@ function get_post_type( $post = null ) { function get_post_type_object( $post_type ) { global $wp_post_types; - if ( is_array( $post_type ) ) - $post_type = reset( $post_type ); - if ( empty($wp_post_types[$post_type]) ) return null; diff --git a/src/wp-includes/query.php b/src/wp-includes/query.php index 322af09e69..165cb6cb3b 100644 --- a/src/wp-includes/query.php +++ b/src/wp-includes/query.php @@ -3076,7 +3076,10 @@ class WP_Query { _make_cat_compat( $this->queried_object ); } } elseif ( $this->is_post_type_archive ) { - $this->queried_object = get_post_type_object( $this->get('post_type') ); + $post_type = $this->get( 'post_type' ); + if ( is_array( $post_type ) ) + $post_type = reset( $post_type ); + $this->queried_object = get_post_type_object( $post_type ); } elseif ( $this->is_posts_page ) { $page_for_posts = get_option('page_for_posts'); $this->queried_object = get_post( $page_for_posts ); @@ -3152,7 +3155,10 @@ class WP_Query { if ( empty( $post_types ) || ! $this->is_post_type_archive ) return (bool) $this->is_post_type_archive; - $post_type_object = get_post_type_object( $this->get( 'post_type' ) ); + $post_type = $this->get( 'post_type' ); + if ( is_array( $post_type ) ) + $post_type = reset( $post_type ); + $post_type_object = get_post_type_object( $post_type ); return in_array( $post_type_object->name, (array) $post_types ); } diff --git a/src/wp-includes/template.php b/src/wp-includes/template.php index 9ae769e090..647d107d93 100644 --- a/src/wp-includes/template.php +++ b/src/wp-includes/template.php @@ -80,7 +80,11 @@ function get_archive_template() { * @return string */ function get_post_type_archive_template() { - $obj = get_post_type_object( get_query_var( 'post_type' ) ); + $post_type = get_query_var( 'post_type' ); + if ( is_array( $post_type ) ) + $post_type = reset( $post_type ); + + $obj = get_post_type_object( $post_type ); if ( ! $obj->has_archive ) return ''; diff --git a/tests/phpunit/tests/query/conditionals.php b/tests/phpunit/tests/query/conditionals.php index f4b271ba19..6c1af44998 100644 --- a/tests/phpunit/tests/query/conditionals.php +++ b/tests/phpunit/tests/query/conditionals.php @@ -699,16 +699,12 @@ class Tests_Query_Conditionals extends WP_UnitTestCase { $this->go_to( "/$cpt_name/" ); $this->assertQueryTrue( 'is_post_type_archive', 'is_archive' ); $this->assertEquals( get_queried_object(), get_post_type_object( $cpt_name ) ); - $this->assertEquals( get_queried_object(), get_post_type_object( array( $cpt_name ) ) ); - $this->assertEquals( get_queried_object(), get_post_type_object( array( $cpt_name, 'post' ) ) ); add_action( 'pre_get_posts', array( $this, 'pre_get_posts_with_type_array' ) ); $this->go_to( "/$cpt_name/" ); $this->assertQueryTrue( 'is_post_type_archive', 'is_archive' ); $this->assertEquals( get_queried_object(), get_post_type_object( 'post' ) ); - $this->assertEquals( get_queried_object(), get_post_type_object( array( 'post' ) ) ); - $this->assertEquals( get_queried_object(), get_post_type_object( array( 'post', $cpt_name ) ) ); remove_action( 'pre_get_posts', array( $this, 'pre_get_posts_with_type_array' ) ); }