Make WordPress Core

Ticket #13096: 13096.patch

File 13096.patch, 3.3 KB (added by SergeyBiryukov, 11 years ago)
  • wp-includes/link-template.php

     
    10951095 * @param bool $previous Optional. Whether to retrieve previous post.
    10961096 * @return mixed Post object if successful. Null if global $post is not set. Empty string if no corresponding post exists.
    10971097 */
    1098 function get_adjacent_post($in_same_cat = false, $excluded_categories = '', $previous = true) {
     1098function get_adjacent_post($in_same_cat = false, $excluded_categories = '', $previous = true, $taxonomy = 'post') {
    10991099        global $post, $wpdb;
    11001100
    1101         if ( empty( $post ) )
     1101        if ( empty( $post ) || !taxonomy_exists( $taxonomy ) )
    11021102                return null;
    11031103
    11041104        $current_post_date = $post->post_date;
     
    11091109                $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";
    11101110
    11111111                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);
    11141114                }
    11151115
    1116                 $posts_in_ex_cats_sql = "AND tt.taxonomy = 'category'";
     1116                $posts_in_ex_cats_sql = $wpdb->prepare("AND tt.taxonomy = '%s'", $taxonomy);
    11171117                if ( !empty($excluded_categories) ) {
    11181118                        $excluded_categories = array_map('intval', explode(' and ', $excluded_categories));
    11191119                        if ( !empty($cat_array) ) {
     
    11221122                        }
    11231123
    11241124                        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);
    11261126                        }
    11271127                }
    11281128        }
     
    11311131        $op = $previous ? '<' : '>';
    11321132        $order = $previous ? 'DESC' : 'ASC';
    11331133
    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" );
    11371137
    11381138        $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);
    11401140        $result = wp_cache_get($query_key, 'counts');
    11411141        if ( false !== $result )
    11421142                return $result;