Make WordPress Core

Ticket #35082: adj-post-fix.diff

File adj-post-fix.diff, 2.5 KB (added by WazzaJB, 10 years ago)

Patch for function

  • wp-includes/link-template.php

    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 
    14861486        $where = '';
    14871487
    14881488        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 
    14921489                if ( ! empty( $excluded_terms ) && ! is_array( $excluded_terms ) ) {
    14931490                        // back-compat, $excluded_terms used to be $excluded_terms with IDs separated by " and "
    14941491                        if ( false !== strpos( $excluded_terms, ' and ' ) ) {
    function get_adjacent_post( $in_same_term = false, $excluded_terms = '', $previo 
    15021499                }
    15031500
    15041501                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
    15051505                        if ( ! is_object_in_taxonomy( $post->post_type, $taxonomy ) )
    15061506                                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                        }
    15081525
    15091526                        // 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 );
    15121528
    1513                         if ( ! $term_array || is_wp_error( $term_array ) )
     1529                        // If the term objects array is now empty
     1530                        if ( ! $term_objects )
    15141531                                return '';
    15151532
    1516                         $where .= " AND tt.term_id IN (" . implode( ',', $term_array ) . ")";
     1533                        $where .= " AND tt.term_id IN (" . implode( ',', $term_ids ) . ")";
    15171534                }
    15181535
    15191536                if ( ! empty( $excluded_terms ) ) {