[wp-trac] [WordPress Trac] #20682: get_adjacent_post generates invalid query for custom post types that don't support categories

WordPress Trac wp-trac at lists.automattic.com
Tue May 15 16:23:22 UTC 2012


#20682: get_adjacent_post generates invalid query for custom post types that don't
support categories
--------------------------+-----------------------------
 Reporter:  batmoo        |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  General       |    Version:
 Severity:  normal        |   Keywords:
--------------------------+-----------------------------
 If a custom post type isn't registered against the category taxonomy,
 setting {{{$in_same_cat}}} results in an invalid query.

 {{{
 SELECT p.* FROM wp_posts AS p
 INNER JOIN wp_term_relationships AS tr ON p.ID = tr.object_id
 INNER JOIN wp_term_taxonomy tt ON tr.term_taxonomy_id =
 tt.term_taxonomy_id
 AND tt.taxonomy = 'category'
 AND tt.term_id IN ()
 WHERE p.post_date > '2012-05-15 16:15:07'
 AND p.post_type = 'book'
 AND p.post_status = 'publish'
 AND tt.taxonomy = 'category'
 ORDER BY p.post_date ASC LIMIT 1
 }}}

 Quick and dirty test code:

 {{{
 add_action( 'init', function() {
         register_post_type( 'book', array( 'label' => 'Books', 'public' =>
 true ) );
 });

 add_action( 'template_redirect', function() {
         if ( is_singular( 'book' ) )
                 var_dump( get_adjacent_post( true, '', false ) );
 } );
 }}}

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/20682>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list