[wp-trac] [WordPress Trac] #18993: is_post_type_archive() returns true in the admin area

WordPress Trac wp-trac at lists.automattic.com
Tue Oct 2 23:11:45 UTC 2012


#18993: is_post_type_archive() returns true in the admin area
----------------------------+-----------------------
 Reporter:  johnbillion     |       Owner:
     Type:  defect (bug)    |      Status:  reopened
 Priority:  normal          |   Milestone:
Component:  Administration  |     Version:  3.3
 Severity:  normal          |  Resolution:
 Keywords:                  |
----------------------------+-----------------------
Changes (by mintindeed):

 * status:  closed => reopened
 * resolution:  invalid =>


Comment:

 Re-opening this, because I was about to file the exact same bug report.

 > This is consistent with all the rest of the conditional tags, which
 aren't expected to be used in the admin area.

 I agree that conditional tags aren't expected to be used in the admin
 area, but I disagree that this is consistent with the rest of the
 conditional tags.  is_post_type_archive() is analogous to is_archive(),
 which returns false in the same scenario.

 Specifically, this example code causes unexpected behaviour when viewing
 the custom post type "Edit" page in the admin ( example.com/wp-
 admin/edit.php?post_type=pmc_gallery ):


 {{{
 // Filter to add pmc_gallery posts to home, category, and tag archives
 add_filter( 'pre_get_posts', function( $query ) {
         if ( ( is_home() || is_archive() )
                 && $query->is_main_query()
         ) {
                 $query->set( 'post_type', array( 'post', 'pmc_gallery' )
 );
         }

         return $query;
 } );

 // Register the pmc_gallery custom post type
 add_action( 'init', function() {
         register_post_type( 'pmc_gallery', array(
                 'labels' => array(
                         'name' => 'Galleries',
                 ),
                 'public' => true,
                 'show_ui' => true,
                 'capability_type' => 'post',
                 'rewrite' => array(
                         'slug' => 'gallery',
                 ),
                 'query_var' => true,
                 'supports' => array(
                         'title', 'editor', 'comments', 'revisions',
 'thumbnail', 'author', 'excerpt'
                 ),
                 'publicly_queryable' => true,
                 'show_ui' => true,
                 'show_in_menu' => true,
                 'taxonomies' => array(
                         'post_tag',
                         'category',
                 ),
                 'has_archive' => true,
                 'hierarchical' => false,
                 'menu_position' => 5,
         ) );
 } );
 }}}

 Expected behaviour:
 pmc_gallery posts are shown on the home page and archive pages, along with
 regular posts.

 Actual behaviour:
 As above, plus /wp-admin/edit.php?post_type=pmc_gallery also shows regular
 posts listed along with pmc_gallery posts, although the counts at the top
 of the screen match only the pmc_gallery post counts.

 Reading the code where $query-> is_post_type_archive is set to true in
 /wp-includes/query.php this behaviour seems like an accident.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/18993#comment:5>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list