WordPress.org

Make WordPress Core

Ticket #13096: get_adjacent_post.patch

File get_adjacent_post.patch, 1.8 KB (added by zerzix, 4 years ago)

diff for get_adjacent_post, not tested

  • wp-includes/link-template.php

     
    989989 * @param bool $previous Optional. Whether to retrieve previous post. 
    990990 * @return string 
    991991 */ 
    992 function get_adjacent_post($in_same_cat = false, $excluded_categories = '', $previous = true) { 
     992function get_adjacent_post($in_same_cat = false, $excluded_categories = '', $previous = true, $taxonomy = 'category') { 
    993993        global $post, $wpdb; 
    994994 
    995995        if ( empty( $post ) ) 
     
    10031003                $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"; 
    10041004 
    10051005                if ( $in_same_cat ) { 
    1006                         $cat_array = wp_get_object_terms($post->ID, 'category', array('fields' => 'ids')); 
    1007                         $join .= " AND tt.taxonomy = 'category' AND tt.term_id IN (" . implode(',', $cat_array) . ")"; 
     1006                        $cat_array = wp_get_object_terms($post->ID, $taxonomy, array('fields' => 'ids')); 
     1007                        $join .= " AND tt.taxonomy = '".$taxonomy."' AND tt.term_id IN (" . implode(',', $cat_array) . ")"; 
    10081008                } 
    10091009 
    1010                 $posts_in_ex_cats_sql = "AND tt.taxonomy = 'category'"; 
     1010                $posts_in_ex_cats_sql = "AND tt.taxonomy = '".$taxonomy."'"; 
    10111011                if ( !empty($excluded_categories) ) { 
    10121012                        $excluded_categories = array_map('intval', explode(' and ', $excluded_categories)); 
    10131013                        if ( !empty($cat_array) ) { 
     
    10161016                        } 
    10171017 
    10181018                        if ( !empty($excluded_categories) ) { 
    1019                                 $posts_in_ex_cats_sql = " AND tt.taxonomy = 'category' AND tt.term_id NOT IN (" . implode($excluded_categories, ',') . ')'; 
     1019                                $posts_in_ex_cats_sql = " AND tt.taxonomy = '".$taxonomy."' AND tt.term_id NOT IN (" . implode($excluded_categories, ',') . ')'; 
    10201020                        } 
    10211021                } 
    10221022        }