Ticket #18614: 18614.5.diff
File 18614.5.diff, 5.6 KB (added by , 11 years ago) |
---|
-
tests/phpunit/tests/query/conditionals.php
648 648 $this->go_to( '/2013/11/41/' ); 649 649 $this->assertQueryTrue( 'is_404' ); 650 650 } 651 652 function test_post_type_archive_with_tax_query() { 653 delete_option( 'rewrite_rules' ); 654 655 $cpt_name = 'ptawtq'; 656 register_post_type( $cpt_name, array( 657 'taxonomies' => array( 'post_tag', 'category' ), 658 'rewrite' => true, 659 'has_archive' => true, 660 'public' => true 661 ) ); 662 663 $tag_id = $this->factory->tag->create( array( 'slug' => 'tag-slug' ) ); 664 $post_id = $this->factory->post->create( array( 'post_type' => $cpt_name ) ); 665 wp_set_object_terms( $post_id, $tag_id, 'post_tag' ); 666 667 $this->go_to( '/ptawtq/' ); 668 $this->assertQueryTrue( 'is_post_type_archive', 'is_archive' ); 669 $this->assertEquals( get_queried_object(), get_post_type_object( $cpt_name ) ); 670 671 add_action( 'pre_get_posts', array( $this, 'pre_get_posts_with_tax_query' ) ); 672 673 $this->go_to( '/ptawtq/' ); 674 $this->assertQueryTrue( 'is_post_type_archive', 'is_archive' ); 675 $this->assertEquals( get_queried_object(), get_post_type_object( $cpt_name ) ); 676 677 remove_action( 'pre_get_posts', array( $this, 'pre_get_posts_with_tax_query' ) ); 678 } 679 680 function pre_get_posts_with_tax_query( &$query ) { 681 $term = get_term_by( 'slug', 'tag-slug', 'post_tag' ); 682 $query->set( 'tax_query', array( 683 array( 'taxonomy' => 'post_tag', 'field' => 'term_id', 'terms' => $term->term_id ) 684 ) ); 685 } 651 686 } -
src/wp-includes/template-loader.php
26 26 $template = false; 27 27 if ( is_404() && $template = get_404_template() ) : 28 28 elseif ( is_search() && $template = get_search_template() ) : 29 elseif ( is_post_type_archive() && $template = get_post_type_archive_template() ) : 29 30 elseif ( is_tax() && $template = get_taxonomy_template() ) : 30 31 elseif ( is_front_page() && $template = get_front_page_template() ) : 31 32 elseif ( is_home() && $template = get_home_template() ) : -
src/wp-includes/template.php
73 73 } 74 74 75 75 /** 76 * Retrieve path of post type archive template in current or parent template. 77 * 78 * @since 3.7.0 79 * 80 * @return string 81 */ 82 function get_post_type_archive_template() { 83 $obj = get_post_type_object( get_query_var( 'post_type' ) ); 84 if ( ! $obj->has_archive ) 85 return ''; 86 87 return get_archive_template(); 88 } 89 90 /** 76 91 * Retrieve path of author template in current or parent template. 77 92 * 78 93 * @since 1.5.0 -
src/wp-includes/query.php
3147 3147 * @return bool 3148 3148 */ 3149 3149 function is_post_type_archive( $post_types = '' ) { 3150 if ( empty( $post_types ) || ! $this->is_post_type_archive )3150 if ( empty( $post_types ) || ! $this->is_post_type_archive ) 3151 3151 return (bool) $this->is_post_type_archive; 3152 3152 3153 $post_type_object = $this->get_queried_object();3153 $post_type_object = get_post_type_object( $this->get( 'post_type' ) ); 3154 3154 3155 3155 return in_array( $post_type_object->name, (array) $post_types ); 3156 3156 } -
src/wp-includes/general-template.php
577 577 $title = single_post_title( '', false ); 578 578 } 579 579 580 // If there's a post type archive 581 if ( is_post_type_archive() ) { 582 $post_type_object = get_post_type_object( get_query_var( 'post_type' ) ); 583 if ( ! $post_type_object->has_archive ) 584 $title = post_type_archive_title( '', false ); 585 } 586 580 587 // If there's a category or tag 581 588 if ( is_category() || is_tag() ) { 582 589 $title = single_term_title( '', false ); … … 595 602 $title = $author->display_name; 596 603 } 597 604 598 // If there's a post type archive599 if ( is_post_type_archive() )605 // Post type archives with has_archive should override terms. 606 if ( is_post_type_archive() && $post_type_object->has_archive ) 600 607 $title = post_type_archive_title( '', false ); 601 608 602 609 // If there's a month … … 696 703 if ( ! is_post_type_archive() ) 697 704 return; 698 705 699 $post_type_obj = get_ queried_object();706 $post_type_obj = get_post_type_object( get_query_var( 'post_type' ) ); 700 707 $title = apply_filters('post_type_archive_title', $post_type_obj->labels->name ); 701 708 702 709 if ( $display ) … … 1670 1677 1671 1678 $args = wp_parse_args( $args, $defaults ); 1672 1679 1673 if ( is_sing le() || is_page() ) {1680 if ( is_singular() ) { 1674 1681 $id = 0; 1675 1682 $post = get_post( $id ); 1676 1683 … … 1678 1685 $title = sprintf( $args['singletitle'], get_bloginfo('name'), $args['separator'], esc_html( get_the_title() ) ); 1679 1686 $href = get_post_comments_feed_link( $post->ID ); 1680 1687 } 1688 } elseif ( is_post_type_archive() ) { 1689 $post_type_obj = get_post_type_object( get_query_var( 'post_type' ) ); 1690 $title = sprintf( $args['posttypetitle'], get_bloginfo( 'name' ), $args['separator'], $post_type_obj->labels->name ); 1691 $href = get_post_type_archive_feed_link( $post_type_obj->name ); 1681 1692 } elseif ( is_category() ) { 1682 1693 $term = get_queried_object(); 1683 1694