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:
parent
9c33c30f5b
commit
0758d4e647
@ -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";
|
$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 ( $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'));
|
$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) . ")";
|
$join .= " AND tt.taxonomy = 'category' AND tt.term_id IN (" . implode(',', $cat_array) . ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user