WordPress.org

Make WordPress Core

Ticket #17807: 17807.2.patch

File 17807.2.patch, 9.0 KB (added by billerickson, 7 years ago)
  • wp-includes/link-template.php

     
    10661066 *
    10671067 * @param bool $in_same_cat Optional. Whether post should be in same category.
    10681068 * @param string $excluded_categories Optional. Excluded categories IDs.
     1069 * @param string $taxonomy Optional. Which taxonomy to use.
    10691070 * @return mixed Post object if successful. Null if global $post is not set. Empty string if no corresponding post exists.
    10701071 */
    1071 function get_previous_post($in_same_cat = false, $excluded_categories = '') {
    1072         return get_adjacent_post($in_same_cat, $excluded_categories);
     1072function get_previous_post($in_same_cat = false, $excluded_categories = '', $taxonomy = 'category') {
     1073        return get_adjacent_post($in_same_cat, $excluded_categories, true, $taxonomy);
    10731074}
    10741075
    10751076/**
     
    10791080 *
    10801081 * @param bool $in_same_cat Optional. Whether post should be in same category.
    10811082 * @param string $excluded_categories Optional. Excluded categories IDs.
     1083 * @param string $taxonomy Optional. Which taxonomy to use.
    10821084 * @return mixed Post object if successful. Null if global $post is not set. Empty string if no corresponding post exists.
    10831085 */
    1084 function get_next_post($in_same_cat = false, $excluded_categories = '') {
    1085         return get_adjacent_post($in_same_cat, $excluded_categories, false);
     1086function get_next_post($in_same_cat = false, $excluded_categories = '', $taxonomy = 'category') {
     1087        return get_adjacent_post($in_same_cat, $excluded_categories, false, $taxonomy);
    10861088}
    10871089
    10881090/**
     
    10951097 * @param bool $in_same_cat Optional. Whether post should be in same category.
    10961098 * @param string $excluded_categories Optional. Excluded categories IDs.
    10971099 * @param bool $previous Optional. Whether to retrieve previous post.
     1100 * @param string $taxonomy Optional. Which taxonomy to use.
    10981101 * @return mixed Post object if successful. Null if global $post is not set. Empty string if no corresponding post exists.
    10991102 */
    1100 function get_adjacent_post($in_same_cat = false, $excluded_categories = '', $previous = true) {
     1103function get_adjacent_post($in_same_cat = false, $excluded_categories = '', $previous = true, $taxonomy = 'category') {
    11011104        global $post, $wpdb;
    11021105
    11031106        if ( empty( $post ) )
     
    11111114                $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";
    11121115
    11131116                if ( $in_same_cat ) {
    1114                         $cat_array = wp_get_object_terms($post->ID, 'category', array('fields' => 'ids'));
    1115                         $join .= " AND tt.taxonomy = 'category' AND tt.term_id IN (" . implode(',', $cat_array) . ")";
     1117                        $cat_array = wp_get_object_terms($post->ID, $taxonomy, array('fields' => 'ids'));
     1118                        $join .= " AND tt.taxonomy = '$taxonomy' AND tt.term_id IN (" . implode(',', $cat_array) . ")";
    11161119                }
    11171120
    1118                 $posts_in_ex_cats_sql = "AND tt.taxonomy = 'category'";
     1121                $posts_in_ex_cats_sql = "AND tt.taxonomy = '$taxonomy'";
    11191122                if ( !empty($excluded_categories) ) {
    11201123                        $excluded_categories = array_map('intval', explode(' and ', $excluded_categories));
    11211124                        if ( !empty($cat_array) ) {
     
    11241127                        }
    11251128
    11261129                        if ( !empty($excluded_categories) ) {
    1127                                 $posts_in_ex_cats_sql = " AND tt.taxonomy = 'category' AND tt.term_id NOT IN (" . implode($excluded_categories, ',') . ')';
     1130                                $posts_in_ex_cats_sql = " AND tt.taxonomy = '$taxonomy' AND tt.term_id NOT IN (" . implode($excluded_categories, ',') . ')';
    11281131                        }
    11291132                }
    11301133        }
     
    11621165 * @param bool $in_same_cat Optional. Whether link should be in same category.
    11631166 * @param string $excluded_categories Optional. Excluded categories IDs.
    11641167 * @param bool $previous Optional, default is true. Whether display link to previous post.
     1168 * @param string $taxonomy Optional. Which taxonomy to use.
    11651169 * @return string
    11661170 */
    1167 function get_adjacent_post_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '', $previous = true) {
     1171function get_adjacent_post_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '', $previous = true, $taxonomy = 'category') {
    11681172        if ( $previous && is_attachment() && is_object( $GLOBALS['post'] ) )
    11691173                $post = & get_post($GLOBALS['post']->post_parent);
    11701174        else
    1171                 $post = get_adjacent_post($in_same_cat,$excluded_categories,$previous);
     1175                $post = get_adjacent_post($in_same_cat, $excluded_categories, $previous, $taxonomy);
    11721176
    11731177        if ( empty($post) )
    11741178                return;
     
    11981202 * @param string $title Optional. Link title format.
    11991203 * @param bool $in_same_cat Optional. Whether link should be in same category.
    12001204 * @param string $excluded_categories Optional. Excluded categories IDs.
     1205 * @param string $taxonomy Optional. Which taxonomy to use.
    12011206 */
    1202 function adjacent_posts_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '') {
    1203         echo get_adjacent_post_rel_link($title, $in_same_cat, $excluded_categories = '', true);
    1204         echo get_adjacent_post_rel_link($title, $in_same_cat, $excluded_categories = '', false);
     1207function adjacent_posts_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '', $taxonomy = 'category') {
     1208        echo get_adjacent_post_rel_link($title, $in_same_cat, $excluded_categories = '', true, $taxonomy);
     1209        echo get_adjacent_post_rel_link($title, $in_same_cat, $excluded_categories = '', false, $taxonomy);
    12051210}
    12061211
    12071212/**
     
    12251230 * @param string $title Optional. Link title format.
    12261231 * @param bool $in_same_cat Optional. Whether link should be in same category.
    12271232 * @param string $excluded_categories Optional. Excluded categories IDs.
     1233 * @param string $taxonomy Optional. Which taxonomy to use.
    12281234 */
    1229 function next_post_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '') {
    1230         echo get_adjacent_post_rel_link($title, $in_same_cat, $excluded_categories = '', false);
     1235function next_post_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '', $taxonomy = 'category') {
     1236        echo get_adjacent_post_rel_link($title, $in_same_cat, $excluded_categories = '', false, $taxonomy);
    12311237}
    12321238
    12331239/**
     
    12381244 * @param string $title Optional. Link title format.
    12391245 * @param bool $in_same_cat Optional. Whether link should be in same category.
    12401246 * @param string $excluded_categories Optional. Excluded categories IDs.
     1247 * @param string $taxonomy Optional. Which taxonomy to use.
    12411248 */
    1242 function prev_post_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '') {
    1243         echo get_adjacent_post_rel_link($title, $in_same_cat, $excluded_categories = '', true);
     1249function prev_post_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '', $taxonomy = 'category') {
     1250        echo get_adjacent_post_rel_link($title, $in_same_cat, $excluded_categories = '', true, $taxonomy);
    12441251}
    12451252
    12461253/**
     
    14081415 * @param string $link Optional. Link permalink format.
    14091416 * @param bool $in_same_cat Optional. Whether link should be in same category.
    14101417 * @param string $excluded_categories Optional. Excluded categories IDs.
     1418 * @param string $taxonomy Optional. Which taxonomy to use.
    14111419 */
    1412 function previous_post_link($format='« %link', $link='%title', $in_same_cat = false, $excluded_categories = '') {
    1413         adjacent_post_link($format, $link, $in_same_cat, $excluded_categories, true);
     1420function previous_post_link($format='« %link', $link='%title', $in_same_cat = false, $excluded_categories = '', $taxonomy = 'category') {
     1421        adjacent_post_link($format, $link, $in_same_cat, $excluded_categories, true, $taxonomy);
    14141422}
    14151423
    14161424/**
     
    14221430 * @param string $link Optional. Link permalink format.
    14231431 * @param bool $in_same_cat Optional. Whether link should be in same category.
    14241432 * @param string $excluded_categories Optional. Excluded categories IDs.
     1433 * @param string $taxonomy Optional. Which taxonomy to use.
    14251434 */
    1426 function next_post_link($format='%link »', $link='%title', $in_same_cat = false, $excluded_categories = '') {
    1427         adjacent_post_link($format, $link, $in_same_cat, $excluded_categories, false);
     1435function next_post_link($format='%link »', $link='%title', $in_same_cat = false, $excluded_categories = '', $taxonomy = 'category') {
     1436        adjacent_post_link($format, $link, $in_same_cat, $excluded_categories, false, $taxonomy);
    14281437}
    14291438
    14301439/**
     
    14391448 * @param bool $in_same_cat Optional. Whether link should be in same category.
    14401449 * @param string $excluded_categories Optional. Excluded categories IDs.
    14411450 * @param bool $previous Optional, default is true. Whether display link to previous post.
     1451 * @param string $taxonomy Optional. Which taxonomy to use.
    14421452 */
    1443 function adjacent_post_link($format, $link, $in_same_cat = false, $excluded_categories = '', $previous = true) {
     1453function adjacent_post_link($format, $link, $in_same_cat = false, $excluded_categories = '', $previous = true, $taxonomy = 'category') {
    14441454        if ( $previous && is_attachment() )
    14451455                $post = & get_post($GLOBALS['post']->post_parent);
    14461456        else
    1447                 $post = get_adjacent_post($in_same_cat, $excluded_categories, $previous);
     1457                $post = get_adjacent_post($in_same_cat, $excluded_categories, $previous, $taxonomy);
    14481458
    14491459        if ( !$post )
    14501460                return;