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: https://develop.svn.wordpress.org/trunk@22472 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Andrew Nacin 2012-11-08 21:16:15 +00:00
parent 9c33c30f5b
commit 0758d4e647
1 changed files with 4 additions and 0 deletions

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) . ")";
}