当前位置: 首页>>代码示例>>PHP>>正文


PHP _get_term_children函数代码示例

本文整理汇总了PHP中_get_term_children函数的典型用法代码示例。如果您正苦于以下问题:PHP _get_term_children函数的具体用法?PHP _get_term_children怎么用?PHP _get_term_children使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了_get_term_children函数的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: ajax_query

 function ajax_query()
 {
     // options
     $options = acf_parse_args($_GET, array('post_id' => 0, 's' => '', 'field_key' => '', 'nonce' => ''));
     // validate
     if (!wp_verify_nonce($options['nonce'], 'acf_nonce')) {
         die;
     }
     // vars
     $r = array();
     $args = array('hide_empty' => false);
     // load field
     $field = acf_get_field($options['field_key']);
     if (!$field) {
         die;
     }
     // search
     if ($options['s']) {
         $args['search'] = $options['s'];
     }
     // filters
     $args = apply_filters('acf/fields/taxonomy/query', $args, $field, $options['post_id']);
     $args = apply_filters('acf/fields/taxonomy/query/name=' . $field['name'], $args, $field, $options['post_id']);
     $args = apply_filters('acf/fields/taxonomy/query/key=' . $field['key'], $args, $field, $options['post_id']);
     // get terms
     $terms = get_terms($field['taxonomy'], $args);
     // sort into hierachial order!
     if (is_taxonomy_hierarchical($field['taxonomy'])) {
         // this will fail if a search has taken place because parents wont exist
         if (empty($args['search'])) {
             $terms = _get_term_children(0, $terms, $field['taxonomy']);
         }
     }
     /// append to r
     foreach ($terms as $term) {
         // add to json
         $r[] = array('id' => $term->term_id, 'text' => $this->get_term_title($term, $field, $options['post_id']));
     }
     // return JSON
     echo json_encode($r);
     die;
 }
开发者ID:pellio11,项目名称:ns-select-project,代码行数:42,代码来源:taxonomy.php

示例2: get_choices

 function get_choices($options = array())
 {
     // defaults
     $options = acf_parse_args($options, array('post_id' => 0, 's' => '', 'field_key' => ''));
     // vars
     $r = array();
     $args = array('hide_empty' => false);
     // load field
     $field = acf_get_field($options['field_key']);
     if (!$field) {
         return false;
     }
     // search
     if ($options['s']) {
         $args['search'] = $options['s'];
     }
     // filters
     $args = apply_filters('acf/fields/taxonomy/query', $args, $field, $options['post_id']);
     $args = apply_filters('acf/fields/taxonomy/query/name=' . $field['name'], $args, $field, $options['post_id']);
     $args = apply_filters('acf/fields/taxonomy/query/key=' . $field['key'], $args, $field, $options['post_id']);
     // get terms
     $terms = get_terms($field['taxonomy'], $args);
     // sort into hierachial order!
     if (is_taxonomy_hierarchical($field['taxonomy'])) {
         // get parent
         $parent = acf_maybe_get($args, 'parent', 0);
         $parent = acf_maybe_get($args, 'child_of', $parent);
         // this will fail if a search has taken place because parents wont exist
         if (empty($args['search'])) {
             $terms = _get_term_children($parent, $terms, $field['taxonomy']);
         }
     }
     /// append to r
     foreach ($terms as $term) {
         // add to json
         $r[] = array('id' => $term->term_id, 'text' => $this->get_term_title($term, $field, $options['post_id']));
     }
     // return
     return $r;
 }
开发者ID:shelbyneilsmith,项目名称:wptools,代码行数:40,代码来源:taxonomy.php

示例3: _get_term_children

/**
 * Get the subset of $terms that are descendants of $term_id.
 *
 * If `$terms` is an array of objects, then _get_term_children() returns an array of objects.
 * If `$terms` is an array of IDs, then _get_term_children() returns an array of IDs.
 *
 * @access private
 * @since 2.3.0
 *
 * @param int    $term_id   The ancestor term: all returned terms should be descendants of `$term_id`.
 * @param array  $terms     The set of terms - either an array of term objects or term IDs - from which those that
 *                          are descendants of $term_id will be chosen.
 * @param string $taxonomy  The taxonomy which determines the hierarchy of the terms.
 * @param array  $ancestors Optional. Term ancestors that have already been identified. Passed by reference, to keep
 *                          track of found terms when recursing the hierarchy. The array of located ancestors is used
 *                          to prevent infinite recursion loops. For performance, `term_ids` are used as array keys,
 *                          with 1 as value. Default empty array.
 * @return array|WP_Error The subset of $terms that are descendants of $term_id.
 */
function _get_term_children($term_id, $terms, $taxonomy, &$ancestors = array())
{
    $empty_array = array();
    if (empty($terms)) {
        return $empty_array;
    }
    $term_list = array();
    $has_children = _get_term_hierarchy($taxonomy);
    if (0 != $term_id && !isset($has_children[$term_id])) {
        return $empty_array;
    }
    // Include the term itself in the ancestors array, so we can properly detect when a loop has occurred.
    if (empty($ancestors)) {
        $ancestors[$term_id] = 1;
    }
    foreach ((array) $terms as $term) {
        $use_id = false;
        if (!is_object($term)) {
            $term = get_term($term, $taxonomy);
            if (is_wp_error($term)) {
                return $term;
            }
            $use_id = true;
        }
        // Don't recurse if we've already identified the term as a child - this indicates a loop.
        if (isset($ancestors[$term->term_id])) {
            continue;
        }
        if ($term->parent == $term_id) {
            if ($use_id) {
                $term_list[] = $term->term_id;
            } else {
                $term_list[] = $term;
            }
            if (!isset($has_children[$term->term_id])) {
                continue;
            }
            $ancestors[$term->term_id] = 1;
            if ($children = _get_term_children($term->term_id, $terms, $taxonomy, $ancestors)) {
                $term_list = array_merge($term_list, $children);
            }
        }
    }
    return $term_list;
}
开发者ID:n8maninger,项目名称:WordPress,代码行数:64,代码来源:taxonomy-functions.php

示例4: acf_get_taxonomy_terms

function acf_get_taxonomy_terms($taxonomies = array())
{
    // force array
    $taxonomies = acf_get_array($taxonomies);
    // get pretty taxonomy names
    $taxonomies = acf_get_pretty_taxonomies($taxonomies);
    // vars
    $r = array();
    // populate $r
    foreach (array_keys($taxonomies) as $taxonomy) {
        // vars
        $label = $taxonomies[$taxonomy];
        $terms = get_terms($taxonomy, array('hide_empty' => false));
        $is_hierarchical = is_taxonomy_hierarchical($taxonomy);
        // bail early i no terms
        if (empty($terms)) {
            continue;
        }
        // sort into hierachial order!
        if ($is_hierarchical) {
            $terms = _get_term_children(0, $terms, $taxonomy);
        }
        // add placeholder
        $r[$label] = array();
        // add choices
        foreach ($terms as $term) {
            $k = "{$taxonomy}:{$term->slug}";
            $r[$label][$k] = acf_get_term_title($term);
        }
    }
    // return
    return $r;
}
开发者ID:finestpixels,项目名称:foodbytes2016,代码行数:33,代码来源:api-helpers.php

示例5: array

/**
 * _get_term_children() - Get array of child terms
 *
 * If $terms is an array of objects, then objects will returned from the function.
 * If $terms is an array of IDs, then an array of ids of children will be returned.
 *
 * @package WordPress
 * @subpackage Taxonomy
 * @access private
 * @since 2.3
 *
 * @param int $term_id Look for this Term ID in $terms
 * @param array $terms List of Term IDs
 * @param string $taxonomy Term Context
 * @return array Empty if $terms is empty else returns full list of child terms.
 */
function &_get_term_children($term_id, $terms, $taxonomy) {
	$empty_array = array();
	if ( empty($terms) )
		return $empty_array;

	$term_list = array();
	$has_children = _get_term_hierarchy($taxonomy);

	if  ( ( 0 != $term_id ) && ! isset($has_children[$term_id]) )
		return $empty_array;

	foreach ( $terms as $term ) {
		$use_id = false;
		if ( !is_object($term) ) {
			$term = get_term($term, $taxonomy);
			if ( is_wp_error( $term ) )
				return $term;
			$use_id = true;
		}

		if ( $term->term_id == $term_id )
			continue;

		if ( $term->parent == $term_id ) {
			if ( $use_id )
				$term_list[] = $term->term_id;
			else
				$term_list[] = $term;

			if ( !isset($has_children[$term->term_id]) )
				continue;

			if ( $children = _get_term_children($term->term_id, $terms, $taxonomy) )
				$term_list = array_merge($term_list, $children);
		}
	}

	return $term_list;
}
开发者ID:staylor,项目名称:develop.svn.wordpress.org,代码行数:55,代码来源:taxonomy.php

示例6: getTerms


//.........这里部分代码省略.........
     if (!empty($number) && !$hierarchical && empty($child_of) && '' === $parent) {
         if ($offset) {
             $limit = 'LIMIT ' . $offset . ',' . $number;
         } else {
             $limit = 'LIMIT ' . $number;
         }
     } else {
         $limit = '';
     }
     if (!empty($search)) {
         $search = like_escape($search);
         $where .= " AND (t.name LIKE '%{$search}%')";
     }
     $selects = array();
     switch ($fields) {
         case 'all':
             $selects = array('t.*', 'tt.*');
             break;
         case 'ids':
         case 'id=>parent':
             $selects = array('t.term_id', 'tt.parent', 'tt.count');
             break;
         case 'names':
             $selects = array('t.term_id', 'tt.parent', 'tt.count', 't.name');
             break;
         case 'count':
             $orderby = '';
             $order = '';
             $selects = array('COUNT(*)');
     }
     $select_this = implode(', ', apply_filters('get_terms_fields', $selects, $args));
     // Add inner to relation table ?
     $join_relation = $join_relation == false ? '' : "INNER JOIN {$wpdb->term_relationships} AS tr ON tt.term_taxonomy_id = tr.term_taxonomy_id";
     $query = "SELECT {$select_this}\r\n\t\t\tFROM {$wpdb->terms} AS t\r\n\t\t\tINNER JOIN {$wpdb->term_taxonomy} AS tt ON t.term_id = tt.term_id\r\n\t\t\t{$join_relation}\r\n\t\t\tWHERE tt.taxonomy IN ({$in_taxonomies})\r\n\t\t\t{$where}\r\n\t\t\t{$orderby} {$order}\r\n\t\t\t{$limit}";
     // GROUP BY t.term_id
     if ('count' == $fields) {
         $term_count = $wpdb->get_var($query);
         return $term_count;
     }
     $terms = $wpdb->get_results($query);
     if ('all' == $fields) {
         update_term_cache($terms);
     }
     if (empty($terms)) {
         wp_cache_add($cache_key, array(), 's-terms');
         $terms = apply_filters('get_terms', array(), $taxonomies, $args);
         return $terms;
     }
     if ($child_of) {
         $children = _get_term_hierarchy($taxonomies[0]);
         if (!empty($children)) {
             $terms =& _get_term_children($child_of, $terms, $taxonomies[0]);
         }
     }
     // Update term counts to include children.
     if ($pad_counts && 'all' == $fields) {
         _pad_term_counts($terms, $taxonomies[0]);
     }
     // Make sure we show empty categories that have children.
     if ($hierarchical && $hide_empty && is_array($terms)) {
         foreach ($terms as $k => $term) {
             if (!$term->count) {
                 $children = _get_term_children($term->term_id, $terms, $taxonomies[0]);
                 if (is_array($children)) {
                     foreach ($children as $child) {
                         if ($child->count) {
                             continue 2;
                         }
                     }
                 }
                 // It really is empty
                 unset($terms[$k]);
             }
         }
     }
     reset($terms);
     $_terms = array();
     if ('id=>parent' == $fields) {
         while ($term = array_shift($terms)) {
             $_terms[$term->term_id] = $term->parent;
         }
         $terms = $_terms;
     } elseif ('ids' == $fields) {
         while ($term = array_shift($terms)) {
             $_terms[] = $term->term_id;
         }
         $terms = $_terms;
     } elseif ('names' == $fields) {
         while ($term = array_shift($terms)) {
             $_terms[] = $term->name;
         }
         $terms = $_terms;
     }
     if (0 < $number && intval(@count($terms)) > $number) {
         $terms = array_slice($terms, $offset, $number);
     }
     wp_cache_add($cache_key, $terms, 's-terms');
     $terms = apply_filters('get_terms', $terms, $taxonomies, $args);
     return $terms;
 }
开发者ID:rongandat,项目名称:best-picture,代码行数:101,代码来源:class.client.tagcloud.php

示例7: getTerms


//.........这里部分代码省略.........
		}

		if ( !empty($search) ) {
			$search = like_escape($search);
			$where .= " AND (t.name LIKE '%$search%')";
		}

		$select_this = '';

		if ( 'all' == $fields ) {
			$select_this = 't.*, tt.*';
		} else if ( 'ids' == $fields ) {
 	        $select_this = 't.term_id, tt.parent, tt.count';
		} else if ( 'names' == $fields ) {
			$select_this = 't.term_id, tt.parent, tt.count, t.name';
		}

		// Limit posts date
		$limitdays_sql = '';
		$limit_days = (int) $limit_days;
		if ( $limit_days != 0 ) {
			$limitdays_sql = 'AND p.post_date_gmt > "' .date( 'Y-m-d H:i:s', time() - $limit_days * 86400 ). '"';
		}

		$query = "SELECT {$select_this}
			FROM {$wpdb->terms} AS t
			INNER JOIN {$wpdb->term_taxonomy} AS tt ON t.term_id = tt.term_id
			INNER JOIN {$wpdb->term_relationships} AS tr ON tt.term_taxonomy_id = tr.term_taxonomy_id
			INNER JOIN {$wpdb->posts} AS p ON tr.object_id = p.ID
			WHERE tt.taxonomy IN ( {$in_taxonomies} )
			AND p.post_date_gmt < '".current_time('mysql')."'
			{$limitdays_sql}
			{$category_sql}
			{$where}
			{$restict_usage}
			GROUP BY t.term_id
			ORDER BY {$order_by}
			{$number_sql}";
		
		if ( 'all' == $fields ) {
			$terms = $wpdb->get_results($query);
			if ( $skip_cache != true ) {
				update_term_cache($terms);
			}
		} else if ( ('ids' == $fields) || ('names' == $fields) ) {
			$terms = $wpdb->get_results($query);
		}

		if ( empty($terms) ) {
			$cache[ $key ] = array();
			wp_cache_set( 'get_terms', $cache, 'terms' );
			$terms = apply_filters('get_terms', array(), $taxonomies, $args);
			return $terms;
		}

		if ( $child_of ) {
		    $children = _get_term_hierarchy($taxonomies[0]);
		    if ( ! empty($children) )
		        $terms = & _get_term_children($child_of, $terms, $taxonomies[0]);
		}

		// Update term counts to include children.
 	    if ( $pad_counts && 'all' == $fields )
	        _pad_term_counts($terms, $taxonomies[0]);

		// Make sure we show empty categories that have children.
		if ( $hierarchical && $hide_empty && is_array($terms) ) {
		    foreach ( $terms as $k => $term ) {
		        if ( ! $term->count ) {
		            $children = _get_term_children($term->term_id, $terms, $taxonomies[0]);
		            if( is_array($children) )
		                foreach ( $children as $child )
		                    if ( $child->count )
		                        continue 2;
		
		            // It really is empty
		            unset($terms[$k]);
		        }
		    }
		}
		reset ( $terms );
		
		$_terms = array();
		if ( 'ids' == $fields ) {
		    while ( $term = array_shift($terms) )
		        $_terms[] = $term->term_id;
		    $terms = $_terms;
		} elseif ( 'names' == $fields ) {
		    while ( $term = array_shift($terms) )
		        $_terms[] = $term->name;
		    $terms = $_terms;
		}
		
		if ( $skip_cache != true ) {
			wp_cache_add( $cache_key, $terms, 'terms' );
		}

		$terms = apply_filters('get_terms', $terms, $taxonomies, $args);
		return $terms;
	}
开发者ID:BackupTheBerlios,项目名称:oos-svn,代码行数:101,代码来源:simple-tags.client.php

示例8: get_terms


//.........这里部分代码省略.........
     $last_changed = wp_cache_get('last_changed', 'terms');
     if (!$last_changed) {
         $last_changed = microtime();
         wp_cache_set('last_changed', $last_changed, 'terms');
     }
     $cache_key = "get_terms:{$key}:{$last_changed}";
     $cache = wp_cache_get($cache_key, 'terms');
     if (false !== $cache) {
         if ('all' === $_fields) {
             $cache = array_map('get_term', $cache);
         }
         return $cache;
     }
     if ('count' == $_fields) {
         return $wpdb->get_var($this->request);
     }
     $terms = $wpdb->get_results($this->request);
     if ('all' == $_fields) {
         update_term_cache($terms);
     }
     // Prime termmeta cache.
     if ($args['update_term_meta_cache']) {
         $term_ids = wp_list_pluck($terms, 'term_id');
         update_termmeta_cache($term_ids);
     }
     if (empty($terms)) {
         wp_cache_add($cache_key, array(), 'terms', DAY_IN_SECONDS);
         return array();
     }
     if ($child_of) {
         foreach ($taxonomies as $_tax) {
             $children = _get_term_hierarchy($_tax);
             if (!empty($children)) {
                 $terms = _get_term_children($child_of, $terms, $_tax);
             }
         }
     }
     // Update term counts to include children.
     if ($args['pad_counts'] && 'all' == $_fields) {
         foreach ($taxonomies as $_tax) {
             _pad_term_counts($terms, $_tax);
         }
     }
     // Make sure we show empty categories that have children.
     if ($hierarchical && $args['hide_empty'] && is_array($terms)) {
         foreach ($terms as $k => $term) {
             if (!$term->count) {
                 $children = get_term_children($term->term_id, $term->taxonomy);
                 if (is_array($children)) {
                     foreach ($children as $child_id) {
                         $child = get_term($child_id, $term->taxonomy);
                         if ($child->count) {
                             continue 2;
                         }
                     }
                 }
                 // It really is empty.
                 unset($terms[$k]);
             }
         }
     }
     $_terms = array();
     if ('id=>parent' == $_fields) {
         foreach ($terms as $term) {
             $_terms[$term->term_id] = $term->parent;
         }
开发者ID:pjsong,项目名称:WordPress,代码行数:67,代码来源:class-wp-term-query.php

示例9: test__get_term_children_handles_cycles_when_terms_argument_contains_objects

 /**
  * @covers ::_get_term_children
  * @ticket 24461
  */
 public function test__get_term_children_handles_cycles_when_terms_argument_contains_objects()
 {
     remove_filter('wp_update_term_parent', 'wp_check_term_hierarchy_for_loops', 10);
     $c1 = $this->factory->category->create_and_get();
     $c2 = $this->factory->category->create_and_get(array('parent' => $c1->term_id));
     $c3 = $this->factory->category->create_and_get(array('parent' => $c2->term_id));
     wp_update_term($c1->term_id, 'category', array('parent' => $c3->term_id));
     add_filter('wp_update_term_parent', 'wp_check_term_hierarchy_for_loops', 10, 3);
     $result = _get_term_children($c1->term_id, array($c1, $c2, $c3), 'category');
     $this->assertEqualSets(array($c2, $c3), $result);
 }
开发者ID:Benrajalu,项目名称:philRaj,代码行数:15,代码来源:getTerms.php

示例10: get_choices

 function get_choices($options = array())
 {
     // defaults
     $options = acf_parse_args($options, array('post_id' => 0, 's' => '', 'field_key' => '', 'paged' => 0));
     // load field
     $field = acf_get_field($options['field_key']);
     if (!$field) {
         return false;
     }
     // vars
     $r = array();
     $args = array();
     $is_hierarchical = is_taxonomy_hierarchical($field['taxonomy']);
     $is_pagination = $options['paged'] > 0;
     $limit = 20;
     $offset = 20 * ($options['paged'] - 1);
     // hide empty
     $args['hide_empty'] = false;
     // pagination
     // - don't bother for hierarchial terms, we will need to load all terms anyway
     if (!$is_hierarchical && $is_pagination) {
         $args['offset'] = $offset;
         $args['number'] = $limit;
     }
     // search
     if ($options['s']) {
         $args['search'] = $options['s'];
     }
     // filters
     $args = apply_filters('acf/fields/taxonomy/query', $args, $field, $options['post_id']);
     $args = apply_filters('acf/fields/taxonomy/query/name=' . $field['name'], $args, $field, $options['post_id']);
     $args = apply_filters('acf/fields/taxonomy/query/key=' . $field['key'], $args, $field, $options['post_id']);
     // get terms
     $terms = get_terms($field['taxonomy'], $args);
     // sort into hierachial order!
     if ($is_hierarchical) {
         // get parent
         $parent = acf_maybe_get($args, 'parent', 0);
         $parent = acf_maybe_get($args, 'child_of', $parent);
         // this will fail if a search has taken place because parents wont exist
         if (empty($args['search'])) {
             $terms = _get_term_children($parent, $terms, $field['taxonomy']);
         }
         // fake pagination
         if ($is_pagination) {
             $terms = array_slice($terms, $offset, $limit);
         }
     }
     /// append to r
     foreach ($terms as $term) {
         // add to json
         $r[] = array('id' => $term->term_id, 'text' => $this->get_term_title($term, $field, $options['post_id']));
     }
     // return
     return $r;
 }
开发者ID:Aqro,项目名称:NewDWM,代码行数:56,代码来源:taxonomy.php

示例11: get_ajax_query

 function get_ajax_query($options = array())
 {
     // defaults
     $options = acf_parse_args($options, array('post_id' => 0, 's' => '', 'field_key' => '', 'paged' => 0));
     // load field
     $field = acf_get_field($options['field_key']);
     if (!$field) {
         return false;
     }
     // bail early if taxonomy does not exist
     if (!taxonomy_exists($field['taxonomy'])) {
         return false;
     }
     // vars
     $results = array();
     $is_hierarchical = is_taxonomy_hierarchical($field['taxonomy']);
     $is_pagination = $options['paged'] > 0;
     $is_search = false;
     $limit = 20;
     $offset = 20 * ($options['paged'] - 1);
     // args
     $args = array('taxonomy' => $field['taxonomy'], 'hide_empty' => false);
     // pagination
     // - don't bother for hierarchial terms, we will need to load all terms anyway
     if ($is_pagination && !$is_hierarchical) {
         $args['number'] = $limit;
         $args['offset'] = $offset;
     }
     // search
     if ($options['s'] !== '') {
         // strip slashes (search may be integer)
         $s = wp_unslash(strval($options['s']));
         // update vars
         $args['search'] = $s;
         $is_search = true;
     }
     // filters
     $args = apply_filters('acf/fields/taxonomy/query', $args, $field, $options['post_id']);
     $args = apply_filters('acf/fields/taxonomy/query/name=' . $field['name'], $args, $field, $options['post_id']);
     $args = apply_filters('acf/fields/taxonomy/query/key=' . $field['key'], $args, $field, $options['post_id']);
     // get terms
     $terms = acf_get_terms($args);
     // sort into hierachial order!
     if ($is_hierarchical) {
         // update vars
         $limit = acf_maybe_get($args, 'number', $limit);
         $offset = acf_maybe_get($args, 'offset', $offset);
         // get parent
         $parent = acf_maybe_get($args, 'parent', 0);
         $parent = acf_maybe_get($args, 'child_of', $parent);
         // this will fail if a search has taken place because parents wont exist
         if (!$is_search) {
             $terms = _get_term_children($parent, $terms, $field['taxonomy']);
         }
         // fake pagination
         if ($is_pagination) {
             $terms = array_slice($terms, $offset, $limit);
         }
     }
     /// append to r
     foreach ($terms as $term) {
         // add to json
         $results[] = array('id' => $term->term_id, 'text' => $this->get_term_title($term, $field, $options['post_id']));
     }
     // vars
     $response = array('results' => $results, 'limit' => $limit);
     // return
     return $response;
 }
开发者ID:developmentDM2,项目名称:Whohaha,代码行数:69,代码来源:taxonomy.php

示例12: getTerms


//.........这里部分代码省略.........
		if ( $hide_empty && !$hierarchical ) {
			if ( $min_usage == 0 ) 
				$where .= ' AND tt.count > 0';
			else 
				$where .= $wpdb->prepare( ' AND tt.count >= %d', $min_usage );
		}

		if ( !empty($search) ) {
			$search = like_escape($search);
			$where .= " AND (t.name LIKE '%$search%')";
		}

		// don't limit the query results when we have to descend the family tree
		if ( ! empty($number) && ! $hierarchical && empty( $child_of ) && '' === $parent ) {
			if( $offset )
				$limit = 'LIMIT ' . $offset . ',' . $number;
			else
				$limit = 'LIMIT ' . $number;

		} else
			$limit = '';

		$selects = array();
		if ( 'all' == $fields )
			$selects = array('t.*', 'tt.*');
		else if ( 'ids' == $fields )
			$selects = array('t.term_id', 'tt.parent', 'tt.count');
		else if ( 'names' == $fields )
			$selects = array('t.term_id', 'tt.parent', 'tt.count', 't.name');

		$select_this = implode(', ', apply_filters( 'get_terms_fields', $selects, $args ));

		$query = "SELECT $select_this 
			FROM $wpdb->terms AS t 
			INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id 
			INNER JOIN $wpdb->term_relationships AS tr ON tt.term_taxonomy_id = tr.term_taxonomy_id
			WHERE tt.taxonomy IN ($in_taxonomies) 
			$where 
			GROUP BY t.term_id
			ORDER BY $orderby $order
			$limit";

		$terms = $wpdb->get_results($query);
		if ( 'all' == $fields ) {
			update_term_cache($terms);
		}

		if ( empty($terms) ) {
			wp_cache_add( $cache_key, array(), 'terms' );
			$terms = apply_filters('get_terms', array(), $taxonomies, $args);
			return $terms;
		}

		if ( $child_of ) {
			$children = _get_term_hierarchy($taxonomies[0]);
			if ( ! empty($children) )
				$terms = & _get_term_children($child_of, $terms, $taxonomies[0]);
		}

		// Update term counts to include children.
		if ( $pad_counts && 'all' == $fields )
			_pad_term_counts($terms, $taxonomies[0]);

		// Make sure we show empty categories that have children.
		if ( $hierarchical && $hide_empty && is_array($terms) ) {
			foreach ( $terms as $k => $term ) {
				if ( ! $term->count ) {
					$children = _get_term_children($term->term_id, $terms, $taxonomies[0]);
					if( is_array($children) )
						foreach ( $children as $child )
							if ( $child->count )
								continue 2;

					// It really is empty
					unset($terms[$k]);
				}
			}
		}
		reset ( $terms );

		$_terms = array();
		if ( 'ids' == $fields ) {
			while ( $term = array_shift($terms) )
				$_terms[] = $term->term_id;
			$terms = $_terms;
		} elseif ( 'names' == $fields ) {
			while ( $term = array_shift($terms) )
				$_terms[] = $term->name;
			$terms = $_terms;
		}

		if ( 0 < $number && intval(@count($terms)) > $number ) {
			$terms = array_slice($terms, $offset, $number);
		}

		wp_cache_add( $cache_key, $terms, 'terms' );

		$terms = apply_filters('get_terms', $terms, $taxonomies, $args);
		return $terms;
	}
开发者ID:BackupTheBerlios,项目名称:oos-svn,代码行数:101,代码来源:client.php

示例13: flt_get_terms

 public static function flt_get_terms($terms, $taxonomies, $args)
 {
     if (!is_array($terms)) {
         return $terms;
     }
     if (empty($terms)) {
         return array();
     }
     global $terms_interceptor;
     if ($terms_interceptor->skip_filtering($taxonomies, $args)) {
         return $terms;
     }
     extract($args, EXTR_SKIP);
     if ('ids' == $fields) {
         return $terms;
     }
     // if some args were forced to prevent core post-processing, restore actual values now
     if (!empty($args['actual_args'])) {
         extract($args['actual_args']);
     }
     if ('all' == $fields) {
         // buffer term names in case they were filtered previously
         $term_names = pp_get_property_array($terms, 'term_id', 'name');
     }
     if (!empty($child_of)) {
         $children = _get_term_hierarchy(reset($taxonomies));
         if (!empty($children)) {
             $terms = _get_term_children($child_of, $terms, reset($taxonomies));
         }
     }
     // Replace DB-stored term counts with actual number of posts this user can read.
     // In addition, without the pp_tally_term_counts() call, WP will hide terms that have no public posts (even if this user can read some of the pvt posts).
     // Post counts will be incremented to include child terms only if $pad_counts is true
     if (!defined('XMLRPC_REQUEST') && 1 == count($taxonomies)) {
         global $pagenow;
         if (!is_admin() || !in_array($pagenow, array('post.php', 'post-new.php'))) {
             if ($hide_empty || !empty($args['actual_args']['hide_empty'])) {
                 // need to tally for all terms in case some were hidden by core function due to lack of public posts
                 $all_terms = get_terms(reset($taxonomies), array('fields' => 'all', 'pp_no_filter' => true, 'hide_empty' => false));
                 PP_TermsQueryLib::tally_term_counts($all_terms, reset($taxonomies), compact('pad_counts', 'skip_teaser', 'post_type'));
                 foreach (array_keys($terms) as $k) {
                     foreach (array_keys($all_terms) as $key) {
                         if ($all_terms[$key]->term_taxonomy_id == $terms[$k]->term_taxonomy_id) {
                             $terms[$k]->count = $all_terms[$key]->count;
                             break;
                         }
                     }
                 }
             } else {
                 PP_TermsQueryLib::tally_term_counts($terms, reset($taxonomies), compact('pad_counts', 'skip_teaser', 'post_type'));
             }
         }
     }
     if ($hide_empty || !empty($args['actual_args']['hide_empty'])) {
         if ($hierarchical) {
             foreach ($taxonomies as $taxonomy) {
                 if (empty($all_terms) || count($taxonomies) > 1) {
                     $all_terms = get_terms($taxonomy, array('fields' => 'all', 'pp_no_filter' => true, 'hide_empty' => false));
                 }
                 // Remove empty terms, but only if their descendants are all empty too.
                 foreach ($terms as $k => $term) {
                     if (!$term->count) {
                         if ($descendants = _get_term_children($term->term_id, $all_terms, $taxonomy)) {
                             foreach ($descendants as $child) {
                                 if ($child->count) {
                                     continue 2;
                                 }
                             }
                         }
                         // It really is empty
                         unset($terms[$k]);
                     }
                 }
             }
         } else {
             foreach ($terms as $key => $term) {
                 if (!$term->count) {
                     unset($terms[$key]);
                 }
             }
         }
     }
     if ($hierarchical && !$parent && count($taxonomies) == 1) {
         require_once PPC_ABSPATH . '/lib/ancestry_lib_pp.php';
         $ancestors = PP_Ancestry::get_term_ancestors(reset($taxonomies));
         // array of all ancestor IDs for keyed term_id, with direct parent first
         $remap_args = array_merge(compact('child_of', 'parent', 'exclude'), array('orderby' => 'name', 'col_id' => 'term_id', 'col_parent' => 'parent'));
         PP_Ancestry::remap_tree($terms, $ancestors, $remap_args);
     }
     reset($terms);
     // === Standard WP post-processing for include, fields, number args ===
     //
     $_terms = array();
     if ('id=>parent' == $fields) {
         while ($term = array_shift($terms)) {
             $_terms[$term->term_id] = $term->parent;
         }
         $terms = $_terms;
     } elseif ('ids' == $fields) {
         while ($term = array_shift($terms)) {
//.........这里部分代码省略.........
开发者ID:severnrescue,项目名称:web,代码行数:101,代码来源:terms-interceptor-counts_pp.php

示例14: getTerms


//.........这里部分代码省略.........
     if (strpos($st_name_like, ' ') != false || strpos($st_name_like, ' ') != null) {
         $tmp = '';
         $sts = explode(' ', $st_name_like);
         foreach ((array) $sts as $st) {
             if (empty($st)) {
                 continue;
             }
             $st = addslashes_gpc($st);
             $tmp .= " t.name LIKE '%{$st}%' OR ";
         }
         // Remove latest OR
         $tmp = substr($tmp, 0, strlen($tmp) - 4);
         $where .= " AND ( {$tmp} ) ";
         unset($tmp);
     } elseif (!empty($st_name_like)) {
         $where .= " AND t.name LIKE '%{$st_name_like}%'";
     }
     if ('' != $parent) {
         $parent = (int) $parent;
         $where .= " AND tt.parent = '{$parent}'";
     }
     if ($hide_empty && !$hierarchical) {
         $where .= ' AND tt.count > 0';
     }
     $number_sql = '';
     if (strpos($number, ',') != false || strpos($number, ',') != null) {
         $number_sql = $number;
     } else {
         $number = (int) $number;
         if ($number != 0) {
             $number_sql = 'LIMIT ' . $number;
         }
     }
     if ('all' == $fields) {
         $select_this = 't.*, tt.*';
     } else {
         if ('ids' == $fields) {
             $select_this = 't.term_id';
         } else {
             if ('names' == $fields) {
                 $select_this == 't.name';
             }
         }
     }
     // Limit posts date
     $limitdays_sql = '';
     $limit_days = (int) $limit_days;
     if ($limit_days != 0) {
         $limitdays_sql = 'AND p.post_date > "' . date('Y-m-d H:i:s', time() - $limit_days * 86400) . '"';
     }
     // Join posts ?
     $inner_posts = '';
     if (!empty($limitdays_sql) | !empty($category_sql)) {
         $inner_posts = "\r\n\t\t\t\tINNER JOIN {$wpdb->term_relationships} AS tr ON tt.term_taxonomy_id = tr.term_taxonomy_id\r\n\t\t\t\tINNER JOIN {$wpdb->posts} AS p ON tr.object_id = p.ID";
     }
     $query = "SELECT DISTINCT {$select_this}\r\n\t\t\tFROM {$wpdb->terms} AS t\r\n\t\t\tINNER JOIN {$wpdb->term_taxonomy} AS tt ON t.term_id = tt.term_id\r\n\t\t\t{$inner_posts}\r\n\t\t\tWHERE tt.taxonomy IN ( {$in_taxonomies} )\r\n\t\t\t{$limitdays_sql}\r\n\t\t\t{$category_sql}\r\n\t\t\t{$where}\r\n\t\t\t{$restict_usage}\r\n\t\t\tORDER BY {$order_by}\r\n\t\t\t{$number_sql}";
     if ('all' == $fields) {
         $terms = $wpdb->get_results($query);
         if ($skip_cache != true) {
             update_term_cache($terms);
         }
     } elseif ('ids' == $fields) {
         $terms = $wpdb->get_col($query);
     }
     if (empty($terms)) {
         return array();
     }
     if ($child_of || $hierarchical) {
         $children = _get_term_hierarchy($taxonomies[0]);
         if (!empty($children)) {
             $terms =& _get_term_children($child_of, $terms, $taxonomies[0]);
         }
     }
     // Update term counts to include children.
     if ($pad_counts) {
         _pad_term_counts($terms, $taxonomies[0]);
     }
     // Make sure we show empty categories that have children.
     if ($hierarchical && $hide_empty) {
         foreach ((array) $terms as $k => $term) {
             if (!$term->count) {
                 $children = _get_term_children($term->term_id, $terms, $taxonomies[0]);
                 foreach ((array) $children as $child) {
                     if ($child->count) {
                         continue 2;
                     }
                 }
                 // It really is empty
                 unset($terms[$k]);
             }
         }
     }
     reset($terms);
     if ($skip_cache != true) {
         $cache[$key] = $terms;
         wp_cache_set('get_terms', $cache, 'terms');
     }
     $terms = apply_filters('get_terms', $terms, $taxonomies, $args);
     return $terms;
 }
开发者ID:nurpax,项目名称:saastafi,代码行数:101,代码来源:simple-tags.php


注:本文中的_get_term_children函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。