diff --git wp-includes/link-template.php wp-includes/link-template.php
index 58b722c..d51b1fe 100644
|
|
|
function get_adjacent_post( $in_same_term = false, $excluded_terms = '', $previo |
| 1486 | 1486 | $where = ''; |
| 1487 | 1487 | |
| 1488 | 1488 | if ( $in_same_term || ! empty( $excluded_terms ) ) { |
| 1489 | | $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"; |
| 1490 | | $where = $wpdb->prepare( "AND tt.taxonomy = %s", $taxonomy ); |
| 1491 | | |
| 1492 | 1489 | if ( ! empty( $excluded_terms ) && ! is_array( $excluded_terms ) ) { |
| 1493 | 1490 | // back-compat, $excluded_terms used to be $excluded_terms with IDs separated by " and " |
| 1494 | 1491 | if ( false !== strpos( $excluded_terms, ' and ' ) ) { |
| … |
… |
function get_adjacent_post( $in_same_term = false, $excluded_terms = '', $previo |
| 1502 | 1499 | } |
| 1503 | 1500 | |
| 1504 | 1501 | if ( $in_same_term ) { |
| | 1502 | $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"; |
| | 1503 | $where .= $wpdb->prepare( "AND tt.taxonomy = %s", $taxonomy ); |
| | 1504 | |
| 1505 | 1505 | if ( ! is_object_in_taxonomy( $post->post_type, $taxonomy ) ) |
| 1506 | 1506 | return ''; |
| 1507 | | $term_array = wp_get_object_terms( $post->ID, $taxonomy, array( 'fields' => 'ids' ) ); |
| | 1507 | |
| | 1508 | // Get all fields rather than just IDs, so we have access to parent ID |
| | 1509 | $term_objects = wp_get_object_terms( $post->ID, $taxonomy, array( 'fields' => 'all' ) ); |
| | 1510 | |
| | 1511 | // Seperated WP error check from empty check as needs to run earlier |
| | 1512 | if( is_wp_error( $term_objects ) ) |
| | 1513 | return ''; |
| | 1514 | |
| | 1515 | // Loop over our terms and store the IDs |
| | 1516 | $term_ids = array(); |
| | 1517 | foreach( $term_objects as $term ) |
| | 1518 | $term_ids[] = (int) $term->term_id; |
| | 1519 | |
| | 1520 | // Loop over the terms and if a terms parent exists, remove the parent |
| | 1521 | foreach( $term_objects as $term ) { |
| | 1522 | if( $term_parent = in_array($term->parent, $term_ids) ) |
| | 1523 | unset($term_ids[$term_parent]); |
| | 1524 | } |
| 1508 | 1525 | |
| 1509 | 1526 | // Remove any exclusions from the term array to include. |
| 1510 | | $term_array = array_diff( $term_array, (array) $excluded_terms ); |
| 1511 | | $term_array = array_map( 'intval', $term_array ); |
| | 1527 | $term_ids = array_diff( $term_ids, (array) $excluded_terms ); |
| 1512 | 1528 | |
| 1513 | | if ( ! $term_array || is_wp_error( $term_array ) ) |
| | 1529 | // If the term objects array is now empty |
| | 1530 | if ( ! $term_objects ) |
| 1514 | 1531 | return ''; |
| 1515 | 1532 | |
| 1516 | | $where .= " AND tt.term_id IN (" . implode( ',', $term_array ) . ")"; |
| | 1533 | $where .= " AND tt.term_id IN (" . implode( ',', $term_ids ) . ")"; |
| 1517 | 1534 | } |
| 1518 | 1535 | |
| 1519 | 1536 | if ( ! empty( $excluded_terms ) ) { |