From 0758d4e6473ac6064c7a82ff19bce19625fa349a Mon Sep 17 00:00:00 2001 From: Andrew Nacin Date: Thu, 8 Nov 2012 21:16:15 +0000 Subject: [PATCH] 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 --- wp-includes/link-template.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/wp-includes/link-template.php b/wp-includes/link-template.php index 10c43564da..2c815542ad 100644 --- a/wp-includes/link-template.php +++ b/wp-includes/link-template.php @@ -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) . ")"; }