Ticket #17807: 17807.2.patch
File 17807.2.patch, 9.0 KB (added by , 8 years ago) |
---|
-
wp-includes/link-template.php
1066 1066 * 1067 1067 * @param bool $in_same_cat Optional. Whether post should be in same category. 1068 1068 * @param string $excluded_categories Optional. Excluded categories IDs. 1069 * @param string $taxonomy Optional. Which taxonomy to use. 1069 1070 * @return mixed Post object if successful. Null if global $post is not set. Empty string if no corresponding post exists. 1070 1071 */ 1071 function get_previous_post($in_same_cat = false, $excluded_categories = '' ) {1072 return get_adjacent_post($in_same_cat, $excluded_categories );1072 function get_previous_post($in_same_cat = false, $excluded_categories = '', $taxonomy = 'category') { 1073 return get_adjacent_post($in_same_cat, $excluded_categories, true, $taxonomy); 1073 1074 } 1074 1075 1075 1076 /** … … 1079 1080 * 1080 1081 * @param bool $in_same_cat Optional. Whether post should be in same category. 1081 1082 * @param string $excluded_categories Optional. Excluded categories IDs. 1083 * @param string $taxonomy Optional. Which taxonomy to use. 1082 1084 * @return mixed Post object if successful. Null if global $post is not set. Empty string if no corresponding post exists. 1083 1085 */ 1084 function get_next_post($in_same_cat = false, $excluded_categories = '' ) {1085 return get_adjacent_post($in_same_cat, $excluded_categories, false );1086 function get_next_post($in_same_cat = false, $excluded_categories = '', $taxonomy = 'category') { 1087 return get_adjacent_post($in_same_cat, $excluded_categories, false, $taxonomy); 1086 1088 } 1087 1089 1088 1090 /** … … 1095 1097 * @param bool $in_same_cat Optional. Whether post should be in same category. 1096 1098 * @param string $excluded_categories Optional. Excluded categories IDs. 1097 1099 * @param bool $previous Optional. Whether to retrieve previous post. 1100 * @param string $taxonomy Optional. Which taxonomy to use. 1098 1101 * @return mixed Post object if successful. Null if global $post is not set. Empty string if no corresponding post exists. 1099 1102 */ 1100 function get_adjacent_post($in_same_cat = false, $excluded_categories = '', $previous = true ) {1103 function get_adjacent_post($in_same_cat = false, $excluded_categories = '', $previous = true, $taxonomy = 'category') { 1101 1104 global $post, $wpdb; 1102 1105 1103 1106 if ( empty( $post ) ) … … 1111 1114 $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"; 1112 1115 1113 1116 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) . ")"; 1116 1119 } 1117 1120 1118 $posts_in_ex_cats_sql = "AND tt.taxonomy = ' category'";1121 $posts_in_ex_cats_sql = "AND tt.taxonomy = '$taxonomy'"; 1119 1122 if ( !empty($excluded_categories) ) { 1120 1123 $excluded_categories = array_map('intval', explode(' and ', $excluded_categories)); 1121 1124 if ( !empty($cat_array) ) { … … 1124 1127 } 1125 1128 1126 1129 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, ',') . ')'; 1128 1131 } 1129 1132 } 1130 1133 } … … 1162 1165 * @param bool $in_same_cat Optional. Whether link should be in same category. 1163 1166 * @param string $excluded_categories Optional. Excluded categories IDs. 1164 1167 * @param bool $previous Optional, default is true. Whether display link to previous post. 1168 * @param string $taxonomy Optional. Which taxonomy to use. 1165 1169 * @return string 1166 1170 */ 1167 function get_adjacent_post_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '', $previous = true ) {1171 function get_adjacent_post_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '', $previous = true, $taxonomy = 'category') { 1168 1172 if ( $previous && is_attachment() && is_object( $GLOBALS['post'] ) ) 1169 1173 $post = & get_post($GLOBALS['post']->post_parent); 1170 1174 else 1171 $post = get_adjacent_post($in_same_cat, $excluded_categories,$previous);1175 $post = get_adjacent_post($in_same_cat, $excluded_categories, $previous, $taxonomy); 1172 1176 1173 1177 if ( empty($post) ) 1174 1178 return; … … 1198 1202 * @param string $title Optional. Link title format. 1199 1203 * @param bool $in_same_cat Optional. Whether link should be in same category. 1200 1204 * @param string $excluded_categories Optional. Excluded categories IDs. 1205 * @param string $taxonomy Optional. Which taxonomy to use. 1201 1206 */ 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 );1207 function 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); 1205 1210 } 1206 1211 1207 1212 /** … … 1225 1230 * @param string $title Optional. Link title format. 1226 1231 * @param bool $in_same_cat Optional. Whether link should be in same category. 1227 1232 * @param string $excluded_categories Optional. Excluded categories IDs. 1233 * @param string $taxonomy Optional. Which taxonomy to use. 1228 1234 */ 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 );1235 function 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); 1231 1237 } 1232 1238 1233 1239 /** … … 1238 1244 * @param string $title Optional. Link title format. 1239 1245 * @param bool $in_same_cat Optional. Whether link should be in same category. 1240 1246 * @param string $excluded_categories Optional. Excluded categories IDs. 1247 * @param string $taxonomy Optional. Which taxonomy to use. 1241 1248 */ 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 );1249 function 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); 1244 1251 } 1245 1252 1246 1253 /** … … 1408 1415 * @param string $link Optional. Link permalink format. 1409 1416 * @param bool $in_same_cat Optional. Whether link should be in same category. 1410 1417 * @param string $excluded_categories Optional. Excluded categories IDs. 1418 * @param string $taxonomy Optional. Which taxonomy to use. 1411 1419 */ 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 );1420 function 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); 1414 1422 } 1415 1423 1416 1424 /** … … 1422 1430 * @param string $link Optional. Link permalink format. 1423 1431 * @param bool $in_same_cat Optional. Whether link should be in same category. 1424 1432 * @param string $excluded_categories Optional. Excluded categories IDs. 1433 * @param string $taxonomy Optional. Which taxonomy to use. 1425 1434 */ 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 );1435 function 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); 1428 1437 } 1429 1438 1430 1439 /** … … 1439 1448 * @param bool $in_same_cat Optional. Whether link should be in same category. 1440 1449 * @param string $excluded_categories Optional. Excluded categories IDs. 1441 1450 * @param bool $previous Optional, default is true. Whether display link to previous post. 1451 * @param string $taxonomy Optional. Which taxonomy to use. 1442 1452 */ 1443 function adjacent_post_link($format, $link, $in_same_cat = false, $excluded_categories = '', $previous = true ) {1453 function adjacent_post_link($format, $link, $in_same_cat = false, $excluded_categories = '', $previous = true, $taxonomy = 'category') { 1444 1454 if ( $previous && is_attachment() ) 1445 1455 $post = & get_post($GLOBALS['post']->post_parent); 1446 1456 else 1447 $post = get_adjacent_post($in_same_cat, $excluded_categories, $previous );1457 $post = get_adjacent_post($in_same_cat, $excluded_categories, $previous, $taxonomy); 1448 1458 1449 1459 if ( !$post ) 1450 1460 return;