Return nothing in get_adjacent_post() when $in_same_cat = true but the post doesn't support (or otherwise have) categories. Avoids SQL error. props batmoo, SergeyBiryukov. fixes #15959.

git-svn-id: http://core.svn.wordpress.org/trunk@22472 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Andrew Nacin 2012-11-08 21:16:15 +00:00
parent e5c1d8d7af
commit 5b8081b787

View File

@ -1133,7 +1133,11 @@ function get_adjacent_post( $in_same_cat = false, $excluded_categories = '', $pr
$join = " INNER JOIN $wpdb->term_relationships AS tr ON p.ID = tr.object_id INNER JOIN $wpdb->term_taxonomy tt ON tr.term_taxonomy_id = tt.term_taxonomy_id";
if ( $in_same_cat ) {
if ( ! is_object_in_taxonomy( $post->post_type, 'category' ) )
return '';
$cat_array = wp_get_object_terms($post->ID, 'category', array('fields' => 'ids'));
if ( ! $cat_array || is_wp_error( $cat_array ) )
return '';
$join .= " AND tt.taxonomy = 'category' AND tt.term_id IN (" . implode(',', $cat_array) . ")";
}