Make WordPress Core


Ignore:
Timestamp:
01/23/2015 02:56:04 PM (9 years ago)
Author:
boonebgorges
Message:

Introduce 'parent' parameter to wp_get_object_terms().

Props mikeschinkel.
Fixes #15675.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/taxonomy.php

    r31248 r31270  
    25562556 * @since 2.3.0
    25572557 * @since 4.2.0 Added support for 'taxonomy', 'parent', and 'term_taxonomy_id' values of `$orderby`.
     2558 *              Introduced `$parent` parameter.
    25582559 *
    25592560 * @global wpdb $wpdb WordPress database abstraction object.
     
    25702571 *                           term objects being returned, 'ids' will return an array of integers, and 'names' an array
    25712572 *                           of strings.
     2573 *     @type int    $parent  Optional. Limit results to the direct children of a given term ID.
    25722574 * }
    25732575 * @return array|WP_Error The requested term data or empty array if no terms found.
     
    25922594    $object_ids = array_map('intval', $object_ids);
    25932595
    2594     $defaults = array('orderby' => 'name', 'order' => 'ASC', 'fields' => 'all');
     2596    $defaults = array(
     2597        'orderby' => 'name',
     2598        'order'   => 'ASC',
     2599        'fields'  => 'all',
     2600        'parent'  => '',
     2601    );
    25952602    $args = wp_parse_args( $args, $defaults );
    25962603
     
    26532660        $select_this = 't.*, tt.*, tr.object_id';
    26542661    }
    2655     $query = "SELECT $select_this FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON tt.term_id = t.term_id INNER JOIN $wpdb->term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy IN ($taxonomies) AND tr.object_id IN ($object_ids) $orderby $order";
     2662
     2663    $where = array(
     2664        "tt.taxonomy IN ($taxonomies)",
     2665        "tr.object_id IN ($object_ids)",
     2666    );
     2667
     2668    if ( '' !== $args['parent'] ) {
     2669        $where[] = $wpdb->prepare( 'tt.parent = %d', $args['parent'] );
     2670    }
     2671
     2672    $where = implode( ' AND ', $where );
     2673
     2674    $query = "SELECT $select_this FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON tt.term_id = t.term_id INNER JOIN $wpdb->term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE $where $orderby $order";
    26562675
    26572676    $objects = false;
Note: See TracChangeset for help on using the changeset viewer.