Ensure that the post type object is the queried object when a post type has been registered with `has_archive => true`. Ensure it is not stomped when decorated with `tax_query`. Adds unit tests.

Props nacin.
Fixes #18614.


Built from https://develop.svn.wordpress.org/trunk@25291


git-svn-id: http://core.svn.wordpress.org/trunk@25255 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Scott Taylor 2013-09-06 22:07:09 +00:00
parent 4079183e42
commit a67d551dac
4 changed files with 33 additions and 6 deletions

View File

@ -577,6 +577,13 @@ function wp_title($sep = '»', $display = true, $seplocation = '') {
$title = single_post_title( '', false );
}
// If there's a post type archive
if ( is_post_type_archive() ) {
$post_type_object = get_post_type_object( get_query_var( 'post_type' ) );
if ( ! $post_type_object->has_archive )
$title = post_type_archive_title( '', false );
}
// If there's a category or tag
if ( is_category() || is_tag() ) {
$title = single_term_title( '', false );
@ -595,8 +602,8 @@ function wp_title($sep = '»', $display = true, $seplocation = '') {
$title = $author->display_name;
}
// If there's a post type archive
if ( is_post_type_archive() )
// Post type archives with has_archive should override terms.
if ( is_post_type_archive() && $post_type_object->has_archive )
$title = post_type_archive_title( '', false );
// If there's a month
@ -696,7 +703,7 @@ function post_type_archive_title( $prefix = '', $display = true ) {
if ( ! is_post_type_archive() )
return;
$post_type_obj = get_queried_object();
$post_type_obj = get_post_type_object( get_query_var( 'post_type' ) );
$title = apply_filters('post_type_archive_title', $post_type_obj->labels->name );
if ( $display )
@ -1670,7 +1677,7 @@ function feed_links_extra( $args = array() ) {
$args = wp_parse_args( $args, $defaults );
if ( is_single() || is_page() ) {
if ( is_singular() ) {
$id = 0;
$post = get_post( $id );
@ -1678,6 +1685,10 @@ function feed_links_extra( $args = array() ) {
$title = sprintf( $args['singletitle'], get_bloginfo('name'), $args['separator'], esc_html( get_the_title() ) );
$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' ) );
$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() ) {
$term = get_queried_object();

View File

@ -3147,10 +3147,10 @@ class WP_Query {
* @return bool
*/
function is_post_type_archive( $post_types = '' ) {
if ( empty( $post_types ) || !$this->is_post_type_archive )
if ( empty( $post_types ) || ! $this->is_post_type_archive )
return (bool) $this->is_post_type_archive;
$post_type_object = $this->get_queried_object();
$post_type_object = get_post_type_object( $this->get( 'post_type' ) );
return in_array( $post_type_object->name, (array) $post_types );
}

View File

@ -26,6 +26,7 @@ if ( defined('WP_USE_THEMES') && WP_USE_THEMES ) :
$template = false;
if ( is_404() && $template = get_404_template() ) :
elseif ( is_search() && $template = get_search_template() ) :
elseif ( is_post_type_archive() && $template = get_post_type_archive_template() ) :
elseif ( is_tax() && $template = get_taxonomy_template() ) :
elseif ( is_front_page() && $template = get_front_page_template() ) :
elseif ( is_home() && $template = get_home_template() ) :

View File

@ -72,6 +72,21 @@ function get_archive_template() {
return get_query_template( 'archive', $templates );
}
/**
* Retrieve path of post type archive template in current or parent template.
*
* @since 3.7.0
*
* @return string
*/
function get_post_type_archive_template() {
$obj = get_post_type_object( get_query_var( 'post_type' ) );
if ( ! $obj->has_archive )
return '';
return get_archive_template();
}
/**
* Retrieve path of author template in current or parent template.
*