• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP update_term_cache函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: wp_get_object_terms


//.........这里部分代码省略.........
    global $wpdb;
    if (!is_array($taxonomies)) {
        $taxonomies = array($taxonomies);
    }
    foreach ((array) $taxonomies as $taxonomy) {
        if (!is_taxonomy($taxonomy)) {
            return new WP_Error('invalid_taxonomy', __('Invalid Taxonomy'));
        }
    }
    if (!is_array($object_ids)) {
        $object_ids = array($object_ids);
    }
    $object_ids = array_map('intval', $object_ids);
    $defaults = array('orderby' => 'name', 'order' => 'ASC', 'fields' => 'all');
    $args = wp_parse_args($args, $defaults);
    $terms = array();
    if (count($taxonomies) > 1) {
        foreach ($taxonomies as $index => $taxonomy) {
            $t = get_taxonomy($taxonomy);
            if (isset($t->args) && is_array($t->args) && $args != array_merge($args, $t->args)) {
                unset($taxonomies[$index]);
                $terms = array_merge($terms, wp_get_object_terms($object_ids, $taxonomy, array_merge($args, $t->args)));
            }
        }
    } else {
        $t = get_taxonomy($taxonomies[0]);
        if (isset($t->args) && is_array($t->args)) {
            $args = array_merge($args, $t->args);
        }
    }
    extract($args, EXTR_SKIP);
    if ('count' == $orderby) {
        $orderby = 'tt.count';
    } else {
        if ('name' == $orderby) {
            $orderby = 't.name';
        } else {
            if ('slug' == $orderby) {
                $orderby = 't.slug';
            } else {
                if ('term_group' == $orderby) {
                    $orderby = 't.term_group';
                } else {
                    if ('term_order' == $orderby) {
                        $orderby = 'tr.term_order';
                    } else {
                        if ('none' == $orderby) {
                            $orderby = '';
                            $order = '';
                        } else {
                            $orderby = 't.term_id';
                        }
                    }
                }
            }
        }
    }
    // tt_ids queries can only be none or tr.term_taxonomy_id
    if ('tt_ids' == $fields && !empty($orderby)) {
        $orderby = 'tr.term_taxonomy_id';
    }
    if (!empty($orderby)) {
        $orderby = "ORDER BY {$orderby}";
    }
    $taxonomies = "'" . implode("', '", $taxonomies) . "'";
    $object_ids = implode(', ', $object_ids);
    $select_this = '';
    if ('all' == $fields) {
        $select_this = 't.*, tt.*';
    } else {
        if ('ids' == $fields) {
            $select_this = 't.term_id';
        } else {
            if ('names' == $fields) {
                $select_this = 't.name';
            } else {
                if ('all_with_object_id' == $fields) {
                    $select_this = 't.*, tt.*, tr.object_id';
                }
            }
        }
    }
    $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}";
    if ('all' == $fields || 'all_with_object_id' == $fields) {
        $terms = array_merge($terms, $wpdb->get_results($query));
        update_term_cache($terms);
    } else {
        if ('ids' == $fields || 'names' == $fields) {
            $terms = array_merge($terms, $wpdb->get_col($query));
        } else {
            if ('tt_ids' == $fields) {
                $terms = $wpdb->get_col("SELECT tr.term_taxonomy_id FROM {$wpdb->term_relationships} AS tr INNER JOIN {$wpdb->term_taxonomy} AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tr.object_id IN ({$object_ids}) AND tt.taxonomy IN ({$taxonomies}) {$orderby} {$order}");
            }
        }
    }
    if (!$terms) {
        $terms = array();
    }
    return apply_filters('wp_get_object_terms', $terms, $object_ids, $taxonomies, $args);
}
开发者ID:klr2003,项目名称:sourceread,代码行数:101,代码来源:taxonomy.php


示例2: taxonomies

 /**
  * Adds tags and categories to the sitemap.
  *
  * @since 1.3
  */
 protected function taxonomies()
 {
     global $wpdb;
     $taxonomy = $this->get_info('content_type');
     if (!($taxonomy == 'category' || $taxonomy == 'post_tag')) {
         return false;
     }
     $tax_not_in = '';
     $limit = $this->getLimit();
     $exclude = $this->get_info('exclude', array());
     if ($exclude && ($ids = wp_parse_id_list($exclude))) {
         $tax_not_in = 't.term_id NOT IN (' . implode(',', $ids) . ') AND';
     }
     // t.slug and tt.taxonomy are necessary to make get_term_link() work properly
     $terms = $wpdb->get_results("SELECT t.term_id, t.slug, tt.taxonomy, MAX(p.post_modified) AS `last_modified`\n\t\t\t FROM {$wpdb->terms} AS t\n\t\t\t INNER JOIN {$wpdb->term_taxonomy} AS tt USING(term_id)\n\t\t\t \tCROSS JOIN {$wpdb->term_relationships} AS tr USING(term_taxonomy_id)\n\t\t\t \tCROSS JOIN {$wpdb->posts} AS p ON p.ID = tr.object_id\n\t\t\t WHERE {$tax_not_in} tt.taxonomy = '{$taxonomy}' AND p.post_type = 'post' AND p.post_status = 'publish'\n\t\t\t GROUP BY t.term_id\n\t\t\t ORDER BY p.post_modified DESC\n\t\t\t LIMIT {$limit}");
     // This hack lets us save a lot of queries that would be performed when we call get_term_link()
     update_term_cache($terms);
     if ($terms) {
         $changefreq = $this->get_info('changefreq', 'none');
         $priority = $this->get_info('priority', 'none');
         foreach ($terms as $term) {
             $this->addUrlItem(get_term_link($term), $term->last_modified, $changefreq, $priority);
         }
     }
 }
开发者ID:MarkSpencerTan,项目名称:webdev,代码行数:30,代码来源:sitetree-xml-factory.class.php


示例3: wp_get_object_terms


//.........这里部分代码省略.........
	$fields = $args['fields'];

	if ( 'count' == $orderby )
		$orderby = 'tt.count';
	else if ( 'name' == $orderby )
		$orderby = 't.name';
	else if ( 'slug' == $orderby )
		$orderby = 't.slug';
	else if ( 'term_group' == $orderby )
		$orderby = 't.term_group';
	else if ( 'term_order' == $orderby )
		$orderby = 'tr.term_order';
	else if ( 'none' == $orderby ) {
		$orderby = '';
		$order = '';
	} else {
		$orderby = 't.term_id';
	}

	// tt_ids queries can only be none or tr.term_taxonomy_id
	if ( ('tt_ids' == $fields) && !empty($orderby) )
		$orderby = 'tr.term_taxonomy_id';

	if ( !empty($orderby) )
		$orderby = "ORDER BY $orderby";

	$order = strtoupper( $order );
	if ( '' !== $order && ! in_array( $order, array( 'ASC', 'DESC' ) ) )
		$order = 'ASC';

	$taxonomies = "'" . implode("', '", array_map( 'esc_sql', $taxonomies ) ) . "'";
	$object_ids = implode(', ', $object_ids);

	$select_this = '';
	if ( 'all' == $fields )
		$select_this = 't.*, tt.*';
	else if ( 'ids' == $fields )
		$select_this = 't.term_id';
	else if ( 'names' == $fields )
		$select_this = 't.name';
	else if ( 'slugs' == $fields )
		$select_this = 't.slug';
	else if ( 'all_with_object_id' == $fields )
		$select_this = 't.*, tt.*, tr.object_id';

	$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";

	$objects = false;
	if ( 'all' == $fields || 'all_with_object_id' == $fields ) {
		$_terms = $wpdb->get_results( $query );
		foreach ( $_terms as $key => $term ) {
			$_terms[$key] = sanitize_term( $term, $taxonomy, 'raw' );
		}
		$terms = array_merge( $terms, $_terms );
		update_term_cache( $terms );
		$objects = true;
	} else if ( 'ids' == $fields || 'names' == $fields || 'slugs' == $fields ) {
		$_terms = $wpdb->get_col( $query );
		$_field = ( 'ids' == $fields ) ? 'term_id' : 'name';
		foreach ( $_terms as $key => $term ) {
			$_terms[$key] = sanitize_term_field( $_field, $term, $term, $taxonomy, 'raw' );
		}
		$terms = array_merge( $terms, $_terms );
	} else if ( 'tt_ids' == $fields ) {
		$terms = $wpdb->get_col("SELECT tr.term_taxonomy_id FROM $wpdb->term_relationships AS tr INNER JOIN $wpdb->term_taxonomy AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tr.object_id IN ($object_ids) AND tt.taxonomy IN ($taxonomies) $orderby $order");
		foreach ( $terms as $key => $tt_id ) {
			$terms[$key] = sanitize_term_field( 'term_taxonomy_id', $tt_id, 0, $taxonomy, 'raw' ); // 0 should be the term id, however is not needed when using raw context.
		}
	}

	if ( ! $terms ) {
		$terms = array();
	} elseif ( $objects && 'all_with_object_id' !== $fields ) {
		$_tt_ids = array();
		$_terms = array();
		foreach ( $terms as $term ) {
			if ( in_array( $term->term_taxonomy_id, $_tt_ids ) ) {
				continue;
			}

			$_tt_ids[] = $term->term_taxonomy_id;
			$_terms[] = $term;
		}
		$terms = $_terms;
	} elseif ( ! $objects ) {
		$terms = array_values( array_unique( $terms ) );
	}
	/**
	 * Filter the terms for a given object or objects.
	 *
	 * @since 2.8.0
	 *
	 * @param array        $terms      An array of terms for the given object or objects.
	 * @param array|int    $object_ids Object ID or array of IDs.
	 * @param array|string $taxonomies A taxonomy or array of taxonomies.
	 * @param array        $args       An array of arguments for retrieving terms for
	 *                                 the given object(s).
	 */
	return apply_filters( 'wp_get_object_terms', $terms, $object_ids, $taxonomies, $args );
}
开发者ID:staylor,项目名称:develop.svn.wordpress.org,代码行数:101,代码来源:taxonomy.php


示例4: get_terms


//.........这里部分代码省略.........
     $where = isset($clauses['where']) ? $clauses['where'] : '';
     $distinct = isset($clauses['distinct']) ? $clauses['distinct'] : '';
     $orderby = isset($clauses['orderby']) ? $clauses['orderby'] : '';
     $order = isset($clauses['order']) ? $clauses['order'] : '';
     $limits = isset($clauses['limits']) ? $clauses['limits'] : '';
     if ($where) {
         $where = "WHERE {$where}";
     }
     $this->sql_clauses['select'] = "SELECT {$distinct} {$fields}";
     $this->sql_clauses['from'] = "FROM {$wpdb->terms} AS t {$join}";
     $this->sql_clauses['orderby'] = $orderby ? "ORDER BY {$orderby} {$order}" : '';
     $this->sql_clauses['limits'] = $limits;
     $this->request = "{$this->sql_clauses['select']} {$this->sql_clauses['from']} {$where} {$this->sql_clauses['orderby']} {$this->sql_clauses['limits']}";
     // $args can be anything. Only use the args defined in defaults to compute the key.
     $key = md5(serialize(wp_array_slice_assoc($args, array_keys($this->query_var_defaults))) . serialize($taxonomies) . $this->request);
     $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);
开发者ID:pjsong,项目名称:WordPress,代码行数:67,代码来源:class-wp-term-query.php


示例5: wp_get_object_terms

/**
 * wp_get_object_terms() - Retrieves the terms associated with the given object(s), in the supplied taxonomies.
 *
 * The following information has to do the $args parameter and for what can be contained in the string
 * or array of that parameter, if it exists.
 *
 * The first argument is called, 'orderby' and has the default value of 'name'. The other value that is
 * supported is 'count'.
 *
 * The second argument is called, 'order' and has the default value of 'ASC'. The only other value that
 * will be acceptable is 'DESC'.
 *
 * The final argument supported is called, 'fields' and has the default value of 'all'. There are
 * multiple other options that can be used instead. Supported values are as follows: 'all', 'ids',
 * 'names', and finally 'all_with_object_id'.
 *
 * The fields argument also decides what will be returned. If 'all' or 'all_with_object_id' is choosen or
 * the default kept intact, then all matching terms objects will be returned. If either 'ids' or 'names'
 * is used, then an array of all matching term ids or term names will be returned respectively.
 *
 * @package WordPress
 * @subpackage Taxonomy
 * @since 2.3
 * @uses $wpdb
 *
 * @param int|array $object_id The id of the object(s) to retrieve.
 * @param string|array $taxonomies The taxonomies to retrieve terms from.
 * @param array|string $args Change what is returned
 * @return array|WP_Error The requested term data or empty array if no terms found. WP_Error if $taxonomy does not exist.
 */
function wp_get_object_terms($object_ids, $taxonomies, $args = array()) {
	global $wpdb;

	if ( !is_array($taxonomies) )
		$taxonomies = array($taxonomies);

	foreach ( $taxonomies as $taxonomy ) {
		if ( ! is_taxonomy($taxonomy) )
			return new WP_Error('invalid_taxonomy', __('Invalid Taxonomy'));
	}

	if ( !is_array($object_ids) )
		$object_ids = array($object_ids);
	$object_ids = array_map('intval', $object_ids);

	$defaults = array('orderby' => 'name', 'order' => 'ASC', 'fields' => 'all');
	$args = wp_parse_args( $args, $defaults );

	$terms = array();
	if ( count($taxonomies) > 1 ) {
		foreach ( $taxonomies as $index => $taxonomy ) {
			$t = get_taxonomy($taxonomy);
			if ( is_array($t->args) && $args != array_merge($args, $t->args) ) {
				unset($taxonomies[$index]);
				$terms = array_merge($terms, wp_get_object_terms($object_ids, $taxonomy, array_merge($args, $t->args)));
			}
		}
	} else {
		$t = get_taxonomy($taxonomies[0]);
		if ( is_array($t->args) )
			$args = array_merge($args, $t->args);
	}

	extract($args, EXTR_SKIP);

	if ( 'count' == $orderby )
		$orderby = 'tt.count';
	else if ( 'name' == $orderby )
		$orderby = 't.name';
	else if ( 'slug' == $orderby )
		$orderby = 't.slug';
	else if ( 'term_group' == $orderby )
		$orderby = 't.term_group';
	else if ( 'term_order' == $orderby )
		$orderby = 'tr.term_order';
	else
		$orderby = 't.term_id';

	$taxonomies = "'" . implode("', '", $taxonomies) . "'";
	$object_ids = implode(', ', $object_ids);

	$select_this = '';
	if ( 'all' == $fields )
		$select_this = 't.*, tt.*';
	else if ( 'ids' == $fields )
		$select_this = 't.term_id';
	else if ( 'names' == $fields )
		$select_this = 't.name';
	else if ( 'all_with_object_id' == $fields )
		$select_this = 't.*, tt.*, tr.object_id';

	$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) ORDER BY $orderby $order";

	if ( 'all' == $fields || 'all_with_object_id' == $fields ) {
		$terms = array_merge($terms, $wpdb->get_results($query));
		update_term_cache($terms);
	} else if ( 'ids' == $fields || 'names' == $fields ) {
		$terms = array_merge($terms, $wpdb->get_col($query));
	} else if ( 'tt_ids' == $fields ) {
		$terms = $wpdb->get_col("SELECT tr.term_taxonomy_id FROM $wpdb->term_relationships AS tr INNER JOIN $wpdb->term_taxonomy AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tr.object_id IN ($object_ids) AND tt.taxonomy IN ($taxonomies) ORDER BY tr.term_taxonomy_id $order");
//.........这里部分代码省略.........
开发者ID:staylor,项目名称:develop.svn.wordpress.org,代码行数:101,代码来源:taxonomy.php


示例6: 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


示例7: flt_get_terms


//.........这里部分代码省略.........
         case 'id=>parent':
             $selects = array('t.term_id', 'tt.term_taxonomy_id', 'tt.parent', 'tt.count');
             break;
         case 'names':
             $selects = array('t.term_id', 'tt.term_taxonomy_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));
     // === BEGIN Role Scoper MODIFICATION: run the query through scoping filter
     //
     $query_base = "SELECT DISTINCT {$select_this} FROM {$wpdb->terms} AS t INNER JOIN {$wpdb->term_taxonomy} AS tt ON t.term_id = tt.term_id WHERE 1=1 AND tt.taxonomy IN ({$in_taxonomies}) {$where} {$parent_or} {$orderby} {$order} {$limit}";
     // only force application of scoped query filter if we're NOT doing a teaser
     if ('all' == $fields) {
         $do_teaser = $scoper->is_front() && empty($skip_teaser) && scoper_get_otype_option('do_teaser', 'post');
     } else {
         $do_teaser = false;
     }
     $query = apply_filters('terms_request_rs', $query_base, $taxonomies[0], array('skip_teaser' => !$do_teaser, 'is_term_admin' => $is_term_admin, 'required_operation' => $required_operation, 'post_type' => $post_type));
     // if no filering was applied because the teaser is enabled, prevent a redundant query
     if (!empty($exclude_tree) || $query_base != $query || $parent || 'all' != $fields) {
         $terms = scoper_get_results($query);
     } else {
         $terms = $results;
     }
     if ('count' == $fields) {
         $term_count = $wpdb->get_var($query);
         return $term_count;
     }
     if ('all' == $fields && empty($include)) {
         update_term_cache($terms);
     }
     // RS: don't cache an empty array, just in case something went wrong
     if (empty($terms)) {
         return array();
     }
     //
     // === END Role Scoper MODIFICATION ===
     // ====================================
     // === BEGIN Role Scoper ADDITION: Support a disjointed terms tree with some parents hidden
     //
     if ('all' == $fields) {
         $ancestors = ScoperAncestry::get_term_ancestors($taxonomy);
         // array of all ancestor IDs for keyed term_id, with direct parent first
         if ($parent > 0 || !$hierarchical) {
             // in Category Edit form, need to list all editable cats even if parent is not editable
             $remap_parents = false;
             $enforce_actual_depth = true;
             $remap_thru_excluded_parent = false;
         } else {
             // if these settings were passed into this get_terms call, use them
             if (is_admin()) {
                 $remap_parents = true;
             } else {
                 if (-1 === $remap_parents) {
                     $remap_parents = scoper_get_option('remap_term_parents');
                 }
                 if ($remap_parents) {
                     if (-1 === $enforce_actual_depth) {
                         $enforce_actual_depth = scoper_get_option('enforce_actual_term_depth');
                     }
                     if (-1 === $remap_thru_excluded_parent) {
                         $remap_thru_excluded_parent = scoper_get_option('remap_thru_excluded_term_parent');
开发者ID:Netsoro,项目名称:gdnlteamgroup,代码行数:67,代码来源:hardway-taxonomy-legacy_rs.php


示例8: 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


示例9: getTaxonomyTerms


//.........这里部分代码省略.........
     /**
      * Filter the fields to select in the terms query.
      *
      * @since 8.1
      *
      * @param array        $select     An array of fields to select for the terms query.
      * @param array        $atts       An array of term query arguments.
      * @param string|array $taxonomies A taxonomy or array of taxonomies.
      */
     $fields = implode(', ', apply_filters('cn_get_terms_fields', $select, $atts, $taxonomies));
     $join = 'INNER JOIN ' . CN_TERM_TAXONOMY_TABLE . ' AS tt ON t.term_id = tt.term_id';
     $pieces = array('fields', 'join', 'where', 'orderBy', 'limit');
     /**
      * Filter the terms query SQL clauses.
      *
      * @since 8.1
      *
      * @param array        $pieces     Terms query SQL clauses.
      * @param string|array $taxonomies A taxonomy or array of taxonomies.
      * @param array        $atts       An array of terms query arguments.
      */
     $clauses = apply_filters('cn_terms_clauses', compact($pieces), $taxonomies, $atts);
     foreach ($pieces as $piece) {
         ${$piece} = isset($clauses[$piece]) ? $clauses[$piece] : '';
     }
     $sql = sprintf('SELECT %1$s FROM %2$s AS t %3$s WHERE %4$s %5$s%6$s', $fields, CN_TERMS_TABLE, $join, implode(' ', $where), $orderBy, empty($limit) ? '' : ' ' . $limit);
     if ('count' == $atts['fields']) {
         $term_count = $wpdb->get_var($sql);
         return $term_count;
     }
     $terms = $wpdb->get_results($sql);
     if ('all' == $atts['fields']) {
         foreach ($taxonomies as $taxonomy) {
             update_term_cache($terms, 'cn_' . $taxonomy);
         }
     }
     if (empty($terms)) {
         wp_cache_add($cache_key, array(), 'cn_terms', DAY_IN_SECONDS);
         $terms = apply_filters('cn_terms', array(), $taxonomies, $atts);
         return $terms;
     }
     if ($atts['child_of']) {
         $children = self::childrenIDs(reset($taxonomies));
         if (!empty($children)) {
             $terms = self::descendants($atts['child_of'], $terms, reset($taxonomies));
         }
     }
     /*
      * @todo Add method to adjust counts based on user visibility permissions.
      */
     // Update term counts to include children.
     if ($atts['pad_counts'] && 'all' == $atts['fields']) {
         self::padCounts($terms, reset($taxonomies));
     }
     // Make sure we show empty categories that have children.
     if ($atts['hierarchical'] && $atts['hide_empty'] && is_array($terms)) {
         foreach ($terms as $k => $term) {
             if (!$term->count) {
                 $children = self::children($term->term_id, reset($taxonomies));
                 if (is_array($children)) {
                     foreach ($children as $child_id) {
                         $child = self::filter($child_id, reset($taxonomies));
                         if ($child->count) {
                             continue 2;
                         }
                     }
开发者ID:VacantFuture,项目名称:Connections,代码行数:67,代码来源:class.terms.php


示例10: test_term_objects_should_not_be_modified_by_update_term_cache

 /**
  * @ticket 35462
  */
 public function test_term_objects_should_not_be_modified_by_update_term_cache()
 {
     register_taxonomy('wptests_tax', 'post');
     $t = self::factory()->term->create(array('taxonomy' => 'wptests_tax'));
     $p = self::factory()->post->create();
     wp_set_object_terms($p, $t, 'wptests_tax');
     $terms = wp_get_object_terms($p, 'wptests_tax', array('fields' => 'all_with_object_id'));
     update_term_cache($terms);
     foreach ($terms as $term) {
         $this->assertSame($p, $term->object_id);
     }
 }
开发者ID:aaemnnosttv,项目名称:develop.git.wordpress.org,代码行数:15,代码来源:cache.php


示例11: get_gmedia_terms


//.........这里部分代码省略.........
  *
  * @see  wp_get_object_terms()
  * @uses $wpdb
  *
  * @param int|array    $object_ids The ID(s) of the object(s) to retrieve.
  * @param string|array $taxonomies The taxonomies to retrieve terms from.
  * @param array|string $args       Change what is returned
  *
  * @return array|WP_Error The requested term data or empty array if no terms found. WP_Error if $taxonomy does not exist.
  */
 function get_gmedia_terms($object_ids, $taxonomies, $args = array())
 {
     /** @var $wpdb wpdb */
     global $wpdb;
     $gmOptions = get_option('gmediaOptions');
     if (!is_array($taxonomies)) {
         $taxonomies = array($taxonomies);
     }
     foreach ((array) $taxonomies as $taxonomy) {
         if (!isset($gmOptions['taxonomies'][$taxonomy])) {
             return new WP_Error('gm_invalid_taxonomy', __('Invalid Taxonomy'));
         }
     }
     if (!is_array($object_ids)) {
         $object_ids = array($object_ids);
     }
     $object_ids = array_map('intval', $object_ids);
     $defaults = array('orderby' => 'name', 'order' => 'ASC', 'fields' => 'all', 'unique' => true);
     $args = wp_parse_args($args, $defaults);
     $terms = array();
     /** @var $orderby
      * @var  $order
      * @var  $fields
      * @var  $unique
      */
     extract($args, EXTR_SKIP);
     if ($unique) {
         $groupby = 'GROUP BY t.term_id';
     } else {
         $groupby = '';
     }
     if ('count' == $orderby) {
         $orderby = 't.count';
     } else {
         if ('name' == $orderby) {
             $orderby = 't.name';
         } else {
             if ('global' == $orderby) {
                 $orderby = 't.global';
             } else {
                 if ('term_order' == $orderby) {
                     $orderby = 'tr.term_order';
                 } else {
                     if ('none' == $orderby) {
                         $orderby = '';
                         $order = '';
                     } else {
                         $orderby = 't.term_id';
                     }
                 }
             }
         }
     }
     if (!empty($orderby)) {
         $orderby = "ORDER BY {$orderby}";
     }
     $taxonomies = "'" . implode("', '", $taxonomies) . "'";
     $object_ids = implode(', ', $object_ids);
     $select_this = '';
     if ('all' == $fields) {
         $select_this = 't.*';
     } else {
         if ('ids' == $fields) {
             $select_this = 't.term_id';
         } else {
             if ('names' == $fields) {
                 $select_this = 't.name';
             } else {
                 if ('all_with_object_id' == $fields) {
                     $select_this = 't.*, tr.gmedia_id';
                     $groupby = '';
                 }
             }
         }
     }
     $query = "SELECT {$select_this} FROM {$wpdb->prefix}gmedia_term AS t INNER JOIN {$wpdb->prefix}gmedia_term_relationships AS tr ON tr.gmedia_term_id = t.term_id WHERE t.taxonomy IN ({$taxonomies}) AND tr.gmedia_id IN ({$object_ids}) {$groupby} {$orderby} {$order}";
     if ('all' == $fields || 'all_with_object_id' == $fields) {
         $terms = array_merge($terms, $wpdb->get_results($query));
         // todo ? maybe move function to plugin core
         update_term_cache($terms);
     } else {
         if ('ids' == $fields || 'names' == $fields) {
             $terms = array_merge($terms, $wpdb->get_col($query));
         }
     }
     if (!$terms) {
         $terms = array();
     }
     return apply_filters('get_gmedia_terms', $terms, $object_ids, $taxonomies, $args);
 }
开发者ID:HugoLS,项目名称:Variation,代码行数:101,代码来源:db.connect.php


示例12: wp_get_object_terms


//.........这里部分代码省略.........
                $terms = array_merge($terms, wp_get_object_terms($object_ids, $taxonomy, array_merge($args, $t->args)));
            }
        }
    } else {
        $t = get_taxonomy($taxonomies[0]);
        if (isset($t->args) && is_array($t->args)) {
            $args = array_merge($args, $t->args);
        }
    }
    extract($args, EXTR_SKIP);
    if ('count' == $orderby) {
        $orderby = 'tt.count';
    } else {
        if ('name' == $orderby) {
            $orderby = 't.name';
        } else {
            if ('slug' == $orderby) {
                $orderby = 't.slug';
            } else {
                if ('term_group' == $orderby) {
                    $orderby = 't.term_group';
                } else {
                    if ('term_order' == $orderby) {
                        $orderby = 'tr.term_order';
                    } else {
                        if ('none' == $orderby) {
                            $orderby = '';
                            $order = '';
                        } else {
                            $orderby = 't.term_id';
                        }
                    }
                }
            }
        }
    }
    // tt_ids queries can only be none or tr.term_taxonomy_id
    if ('tt_ids' == $fields && !empty($orderby)) {
        $orderby = 'tr.term_taxonomy_id';
    }
    if (!empty($orderby)) {
        $orderby = "ORDER BY {$orderby}";
    }
    $order = strtoupper($order);
    if ('' !== $order && !in_array($order, array('ASC', 'DESC'))) {
        $order = 'ASC';
    }
    $taxonomies = "'" . implode("', '", $taxonomies) . "'";
    $object_ids = implode(', ', $object_ids);
    $select_this = '';
    if ('all' == $fields) {
        $select_this = 't.*, tt.*';
    } else {
        if ('ids' == $fields) {
            $select_this = 't.term_id';
        } else {
            if ('names' == $fields) {
                $select_this = 't.name';
            } else {
                if ('slugs' == $fields) {
                    $select_this = 't.slug';
                } else {
                    if ('all_with_object_id' == $fields) {
                        $select_this = 't.*, tt.*, tr.object_id';
                    }
                }
            }
        }
    }
    $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}";
    if ('all' == $fields || 'all_with_object_id' == $fields) {
        $_terms = $wpdb->get_results($query);
        foreach ($_terms as $key => $term) {
            $_terms[$key] = sanitize_term($term, $taxonomy, 'raw');
        }
        $terms = array_merge($terms, $_terms);
        update_term_cache($terms);
    } else {
        if ('ids' == $fields || 'names' == $fields || 'slugs' == $fields) {
            $_terms = $wpdb->get_col($query);
            $_field = 'ids' == $fields ? 'term_id' : 'name';
            foreach ($_terms as $key => $term) {
                $_terms[$key] = sanitize_term_field($_field, $term, $term, $taxonomy, 'raw');
            }
            $terms = array_merge($terms, $_terms);
        } else {
            if ('tt_ids' == $fields) {
                $terms = $wpdb->get_col("SELECT tr.term_taxonomy_id FROM {$wpdb->term_relationships} AS tr INNER JOIN {$wpdb->term_taxonomy} AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tr.object_id IN ({$object_ids}) AND tt.taxonomy IN ({$taxonomies}) {$orderby} {$order}");
                foreach ($terms as $key => $tt_id) {
                    $terms[$key] = sanitize_term_field('term_taxonomy_id', $tt_id, 0, $taxonomy, 'raw');
                    // 0 should be the term id, however is not needed when using raw context.
                }
            }
        }
    }
    if (!$terms) {
        $terms = array();
    }
    return apply_filters('wp_get_object_terms', $terms, $object_ids, $taxonomies, $args);
}
开发者ID:dev-lav,项目名称:htdocs,代码行数:101,代码来源:taxonomy.php


示例13: wp_get_object_terms

/**
 * Returns the terms associated with the given object(s), in the supplied taxonomies.
 * @param int|array $object_id The id of the object(s)) to retrieve for.
 * @param string|array $taxonomies The taxonomies to retrieve terms from.
 * @return array The requested term data.
 */
function wp_get_object_terms($object_ids, $taxonomies, $args = array())
{
    global $wpdb;
    if (!is_array($taxonomies)) {
        $taxonomies = array($taxonomies);
    }
    foreach ($taxonomies as $taxonomy) {
        if (!is_taxonomy($taxonomy)) {
            return new WP_Error('invalid_taxonomy', __('Invalid Taxonomy'));
        }
    }
    if (!is_array($object_ids)) {
        $object_ids = array($object_ids);
    }
    $object_ids = array_map('intval', $object_ids);
    $defaults = array('orderby' => 'name', 'order' => 'ASC', 'fields' => 'all');
    $args = wp_parse_args($args, $defaults);
    extract($args, EXTR_SKIP);
    if ('count' == $orderby) {
        $orderby = 'tt.count';
    } else {
        if ('name' == $orderby) {
            $orderby = 't.name';
        }
    }
    $taxonomies = "'" . implode("', '", $taxonomies) . "'";
    $object_ids = implode(', ', $object_ids);
    if ('all' == $fields) {
        $select_this = 't.*, tt.*';
    } else {
        if ('ids' == $fields) {
            $select_this = 't.term_id';
        } else {
            if ('names' == $fields) {
                $select_this = 't.name';
            } else {
                if ('all_with_object_id' == $fields) {
                    $select_this = 't.*, tt.*, tr.object_id';
                }
            }
        }
    }
    $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}) ORDER BY {$orderby} {$order}";
    if ('all' == $fields || 'all_with_object_id' == $fields) {
        $terms = $wpdb->get_results($query);
        update_term_cache($terms);
    } else {
        if ('ids' == $fields || 'names' == $fields) {
            $terms = $wpdb->get_col($query);
        } else {
            if ('tt_ids' == $fields) {
                $terms = $wpdb->get_col("SELECT tr.term_taxonomy_id FROM {$wpdb->term_relationships} AS tr INNER JOIN {$wpdb->term_taxonomy} AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tr.object_id IN ({$object_ids}) AND tt.taxonomy IN ({$taxonomies}) ORDER BY tr.term_taxonomy_id {$order}");
            }
        }
    }
    if (!$terms) {
        return array();
    }
    return $terms;
}
开发者ID:helmonaut,项目名称:owb-mirror,代码行数:66,代码来源:taxonomy.php


示例14: filter_request

 /**
  * Function called when query parameters are processed by Wordpress.
  * 
  * @param $query query parameters
  * @return array() $query processed
  *
  * @since 1.0
  */
 function filter_request($query)
 {
     global $q_config, $wp_query, $wp;
     if (isset($wp->matched_query)) {
         $query = wp_parse_args($wp->matched_query);
     }
     foreach (get_post_types() as $post_type) {
         if (array_key_exists($post_type, $query) && !in_array($post_type, array('post', 'page'))) {
             $query['post_type'] = $post_type;
         }
     }
     $page_foundit = false;
     // -> page
     if (isset($query['pagename']) || isset($query['page_id'])) {
         $page = wp_cache_get('qts_page_request');
         if (!$page) {
             $page = isset($query['page_id']) ? get_page($query['page_id']) : $this->get_page_by_path($query['pagename']);
         }
         if (!$page) {
             return $query;
         }
         $id = $page->ID;
         $cache_array = array($page);
         update_post_caches($cache_array, 'page');
         // caching query :)
         wp_cache_delete('qts_page_request');
         $query['pagename'] = get_page_uri($page);
         $function = 'get_page_link';
         // -> custom post type
     } elseif (isset($query['post_type'])) {
         $page_slug = isset($query['name']) && !empty($query['name']) ? $query['name'] : $query[$query['post_type']];
         $page = $this->get_page_by_path($page_slug, OBJECT, $query['post_type']);
         if (!$page) {
             return $query;
         }
         $id = $page->ID;
         $cache_array = array($page);
         update_post_caches($cache_array, $query['post_type']);
         // caching query :)
         $query['name'] = $query[$query['post_type']] = get_page_uri($page);
         $function = 'get_post_permalink';
         // -> post
     } elseif (isset($query['name']) || isset($query['p'])) {
         $post = isset($query['p']) ? get_post($query['p']) : $this-&g 

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP update_term_meta函数代码示例发布时间:2022-05-23
下一篇:
PHP update_task_list函数代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap