Ticket #13096: 13096.patch
| File 13096.patch, 3.3 KB (added by SergeyBiryukov, 2 years ago) |
|---|
-
wp-includes/link-template.php
1095 1095 * @param bool $previous Optional. Whether to retrieve previous post. 1096 1096 * @return mixed Post object if successful. Null if global $post is not set. Empty string if no corresponding post exists. 1097 1097 */ 1098 function get_adjacent_post($in_same_cat = false, $excluded_categories = '', $previous = true ) {1098 function get_adjacent_post($in_same_cat = false, $excluded_categories = '', $previous = true, $taxonomy = 'post') { 1099 1099 global $post, $wpdb; 1100 1100 1101 if ( empty( $post ) )1101 if ( empty( $post ) || !taxonomy_exists( $taxonomy ) ) 1102 1102 return null; 1103 1103 1104 1104 $current_post_date = $post->post_date; … … 1109 1109 $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"; 1110 1110 1111 1111 if ( $in_same_cat ) { 1112 $cat_array = wp_get_object_terms($post->ID, 'category', array('fields' => 'ids'));1113 $join .= " AND tt.taxonomy = 'category' AND tt.term_id IN (" . implode(',', $cat_array) . ")";1112 $cat_array = wp_get_object_terms($post->ID, $taxonomy, array('fields' => 'ids')); 1113 $join .= $wpdb->prepare(" AND tt.taxonomy = '%s' AND tt.term_id IN (" . implode(',', $cat_array) . ")", $taxonomy); 1114 1114 } 1115 1115 1116 $posts_in_ex_cats_sql = "AND tt.taxonomy = 'category'";1116 $posts_in_ex_cats_sql = $wpdb->prepare("AND tt.taxonomy = '%s'", $taxonomy); 1117 1117 if ( !empty($excluded_categories) ) { 1118 1118 $excluded_categories = array_map('intval', explode(' and ', $excluded_categories)); 1119 1119 if ( !empty($cat_array) ) { … … 1122 1122 } 1123 1123 1124 1124 if ( !empty($excluded_categories) ) { 1125 $posts_in_ex_cats_sql = " AND tt.taxonomy = 'category' AND tt.term_id NOT IN (" . implode($excluded_categories, ',') . ')';1125 $posts_in_ex_cats_sql = $wpdb->prepare(" AND tt.taxonomy = '%s' AND tt.term_id NOT IN (" . implode($excluded_categories, ',') . ')', $taxonomy); 1126 1126 } 1127 1127 } 1128 1128 } … … 1131 1131 $op = $previous ? '<' : '>'; 1132 1132 $order = $previous ? 'DESC' : 'ASC'; 1133 1133 1134 $join = apply_filters( "get_{$adjacent}_ post_join", $join, $in_same_cat, $excluded_categories );1135 $where = apply_filters( "get_{$adjacent}_ post_where", $wpdb->prepare("WHERE p.post_date $op %s AND p.post_type = %s AND p.post_status = 'publish' $posts_in_ex_cats_sql", $current_post_date, $post->post_type), $in_same_cat, $excluded_categories );1136 $sort = apply_filters( "get_{$adjacent}_ post_sort", "ORDER BY p.post_date $order LIMIT 1" );1134 $join = apply_filters( "get_{$adjacent}_{$taxonomy}_join", $join, $in_same_cat, $excluded_categories ); 1135 $where = apply_filters( "get_{$adjacent}_{$taxonomy}_where", $wpdb->prepare("WHERE p.post_date $op %s AND p.post_type = %s AND p.post_status = 'publish' $posts_in_ex_cats_sql", $current_post_date, $post->post_type), $in_same_cat, $excluded_categories ); 1136 $sort = apply_filters( "get_{$adjacent}_{$taxonomy}_sort", "ORDER BY p.post_date $order LIMIT 1" ); 1137 1137 1138 1138 $query = "SELECT p.* FROM $wpdb->posts AS p $join $where $sort"; 1139 $query_key = 'adjacent_post_'. md5($query);1139 $query_key = "adjacent_{$taxonomy}_" . md5($query); 1140 1140 $result = wp_cache_get($query_key, 'counts'); 1141 1141 if ( false !== $result ) 1142 1142 return $result;
