Opened 14 years ago
Closed 14 years ago
#20682 closed defect (bug) (duplicate)
get_adjacent_post generates invalid query for custom post types that don't support categories
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Milestone: | Priority: | normal | |
| Severity: | normal | Version: | |
| Component: | Posts, Post Types | Keywords: | |
| Focuses: | Cc: |
Description
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 ) );
} );
Change History (1)
Note: See
TracTickets for help on using
tickets.
#15959