本文整理汇总了PHP中_get_term_hierarchy函数的典型用法代码示例。如果您正苦于以下问题:PHP _get_term_hierarchy函数的具体用法?PHP _get_term_hierarchy怎么用?PHP _get_term_hierarchy使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了_get_term_hierarchy函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: cat_rows
function cat_rows( $parent = 0, $level = 0, $categories = 0 ) {
if ( !$categories ) {
$args = array('hide_empty' => 0);
if ( !empty($_GET['s']) )
$args['search'] = $_GET['s'];
$categories = get_categories( $args );
}
$children = _get_term_hierarchy('category');
if ( $categories ) {
ob_start();
foreach ( $categories as $category ) {
if ( $category->parent == $parent) {
echo "\t" . _cat_row( $category, $level );
if ( isset($children[$category->term_id]) )
cat_rows( $category->term_id, $level +1, $categories );
}
}
$output = ob_get_contents();
ob_end_clean();
$output = apply_filters('cat_rows', $output);
echo $output;
} else {
return false;
}
}
示例2: _cat_rows
/**
* {@internal Missing Short Description}}
*
* @since unknown
*
* @param unknown_type $categories
* @param unknown_type $count
* @param unknown_type $parent
* @param unknown_type $level
* @param unknown_type $page
* @param unknown_type $per_page
* @return unknown
*/
function _cat_rows( $categories, &$count, $parent = 0, $level = 0, $page = 1, $per_page = 20 ) {
if ( empty($categories) ) {
$args = array('hide_empty' => 0);
if ( !empty($_GET['s']) )
$args['search'] = $_GET['s'];
$categories = get_categories( $args );
}
if ( !$categories )
return false;
$children = _get_term_hierarchy('category');
$start = ($page - 1) * $per_page;
$end = $start + $per_page;
$i = -1;
ob_start();
foreach ( $categories as $category ) {
if ( $count >= $end )
break;
$i++;
if ( $category->parent != $parent )
continue;
// If the page starts in a subtree, print the parents.
if ( $count == $start && $category->parent > 0 ) {
$my_parents = array();
while ( $my_parent) {
$my_parent = get_category($my_parent);
$my_parents[] = $my_parent;
if ( !$my_parent->parent )
break;
$my_parent = $my_parent->parent;
}
$num_parents = count($my_parents);
while( $my_parent = array_pop($my_parents) ) {
echo "\t" . _cat_row( $my_parent, $level - $num_parents );
$num_parents--;
}
}
if ( $count >= $start )
echo "\t" . _cat_row( $category, $level );
unset($categories[$i]); // Prune the working set
$count++;
if ( isset($children[$category->term_id]) )
_cat_rows( $categories, $count, $category->term_id, $level + 1, $page, $per_page );
}
$output = ob_get_contents();
ob_end_clean();
echo $output;
}
示例3: vp_flush_regenerable_options
function vp_flush_regenerable_options()
{
wp_cache_flush();
$taxonomies = get_taxonomies();
foreach ($taxonomies as $taxonomy) {
delete_option("{$taxonomy}_children");
// Regenerate {$taxonomy}_children
_get_term_hierarchy($taxonomy);
}
}
示例4: import_end
/**
* Performs post-import cleanup of files and the cache
*/
function import_end()
{
wp_import_cleanup($this->id);
wp_cache_flush();
foreach (get_taxonomies() as $tax) {
delete_option("{$tax}_children");
_get_term_hierarchy($tax);
}
wp_defer_term_counting(false);
wp_defer_comment_counting(false);
do_action('import_end');
}
示例5: import_end
public function import_end()
{
wp_cache_flush();
foreach (get_taxonomies() as $tax) {
delete_option("{$tax}_children");
_get_term_hierarchy($tax);
}
wp_defer_term_counting(false);
wp_defer_comment_counting(false);
echo '<p>' . __('All done.', 'wordpress-importer') . ' <a href="' . admin_url() . '">' . __('Have fun!', 'wordpress-importer') . '</a>' . '</p>';
echo '<p>' . __('Remember to update the passwords and roles of imported users.', 'wordpress-importer') . '</p>';
do_action('import_end');
}
示例6: test_should_rebuild_split_term_taxonomy_hierarchy
/**
* @ticket 30335
*/
public function test_should_rebuild_split_term_taxonomy_hierarchy()
{
global $wpdb;
register_taxonomy('wptests_tax_3', 'post');
register_taxonomy('wptests_tax_4', 'post', array('hierarchical' => true));
$t1 = wp_insert_term('Foo1', 'wptests_tax_3');
$t2 = wp_insert_term('Foo1 Parent', 'wptests_tax_4');
$t3 = wp_insert_term('Foo1', 'wptests_tax_4', array('parent' => $t2['term_id']));
// Manually modify because shared terms shouldn't naturally occur.
$wpdb->update($wpdb->term_taxonomy, array('term_id' => $t1['term_id']), array('term_taxonomy_id' => $t3['term_taxonomy_id']), array('%d'), array('%d'));
$th = _get_term_hierarchy('wptests_tax_4');
$new_term_id = _split_shared_term($t1['term_id'], $t3['term_taxonomy_id']);
$t2_children = get_term_children($t2['term_id'], 'wptests_tax_4');
$this->assertEquals(array($new_term_id), $t2_children);
}
示例7: cat_rows
/**
* {@internal Missing Short Description}}
*
* @since unknown
*
* @param unknown_type $parent
* @param unknown_type $level
* @param unknown_type $categories
* @param unknown_type $page
* @param unknown_type $per_page
*/
function cat_rows($parent = 0, $level = 0, $categories = 0, $page = 1, $per_page = 20)
{
$count = 0;
if (empty($categories)) {
$args = array('hide_empty' => 0);
if (!empty($_GET['s'])) {
$args['search'] = $_GET['s'];
}
$categories = get_categories($args);
if (empty($categories)) {
return false;
}
}
$children = _get_term_hierarchy('category');
_cat_rows($parent, $level, $categories, $children, $page, $per_page, $count);
}
示例8: wpsc_add_variation_set
/**
* Add new variation set via AJAX.
*
* If the variation set name is the same as an existing variation set,
* the children variant terms will be added inside that existing set.
* @since 3.8.8
*/
function wpsc_add_variation_set()
{
$new_variation_set = $_POST['variation_set'];
$variants = preg_split('/\\s*,\\s*/', $_POST['variants']);
$parent_term_exists = term_exists($new_variation_set, 'wpsc-variation');
// only use an existing parent ID if the term is not a child term
if ($parent_term_exists) {
$parent_term = get_term($parent_term_exists['term_id'], 'wpsc-variation');
if ($parent_term->parent == '0') {
$variation_set_id = $parent_term_exists['term_id'];
}
}
if (empty($variation_set_id)) {
$results = wp_insert_term($new_variation_set, 'wpsc-variation');
if (is_wp_error($results)) {
die('-1');
}
$variation_set_id = $results['term_id'];
}
$inserted_variants = array();
if (!empty($variation_set_id)) {
foreach ($variants as $variant) {
$results = wp_insert_term($variant, 'wpsc-variation', array('parent' => $variation_set_id));
if (is_wp_error($results)) {
die('-1');
}
$inserted_variants[] = $results['term_id'];
}
require_once 'includes/walker-variation-checklist.php';
/* --- DIRTY HACK START --- */
/*
There's a bug with term cache in WordPress core. See http://core.trac.wordpress.org/ticket/14485.
The next 3 lines will delete children term cache for wpsc-variation.
Without this hack, the new child variations won't be displayed on "Variations" page and
also won't be displayed in wp_terms_checklist() call below.
*/
clean_term_cache($variation_set_id, 'wpsc-variation');
delete_option('wpsc-variation_children');
wp_cache_set('last_changed', 1, 'terms');
_get_term_hierarchy('wpsc-variation');
/* --- DIRTY HACK END --- */
wp_terms_checklist((int) $_POST['post_id'], array('taxonomy' => 'wpsc-variation', 'descendants_and_self' => $variation_set_id, 'walker' => new WPSC_Walker_Variation_Checklist($inserted_variants), 'checked_ontop' => false));
}
exit;
}
示例9: test_hierachy_invalidation
/**
* @ticket 14485
*/
function test_hierachy_invalidation()
{
$tax = 'burrito';
register_taxonomy($tax, 'post', array('hierarchical' => true));
$this->assertTrue(get_taxonomy($tax)->hierarchical);
$step = 1;
$parent_id = 0;
$children = 0;
foreach (range(1, 9) as $i) {
switch ($step) {
case 1:
$parent = wp_insert_term('Parent' . $i, $tax);
$parent_id = $parent['term_id'];
break;
case 2:
$parent = wp_insert_term('Child' . $i, $tax, array('parent' => $parent_id));
$parent_id = $parent['term_id'];
$children++;
break;
case 3:
wp_insert_term('Grandchild' . $i, $tax, array('parent' => $parent_id));
$parent_id = 0;
$children++;
break;
}
$terms = get_terms($tax, array('hide_empty' => false));
$this->assertEquals($i, count($terms));
if ($i > 1) {
$hierarchy = _get_term_hierarchy($tax);
$this->assertNotEmpty($hierarchy);
$this->assertEquals($children, count($hierarchy, COUNT_RECURSIVE) - count($hierarchy));
}
if ($i % 3 === 0) {
$step = 1;
} else {
$step++;
}
}
_unregister_taxonomy($tax);
}
示例10: getTerms
/**
* Extended get_terms public static function support
* - Limit category
* - Limit days
* - Selection restrict
* - Min usage
*
* @param string|array $taxonomies
* @param string $args
* @return array
*/
public static function getTerms($taxonomies, $args = '')
{
global $wpdb;
$empty_array = array();
$join_relation = false;
$single_taxonomy = false;
if (!is_array($taxonomies)) {
$single_taxonomy = true;
$taxonomies = array($taxonomies);
}
foreach ((array) $taxonomies as $taxonomy) {
if (!taxonomy_exists($taxonomy)) {
$error = new WP_Error('invalid_taxonomy', __('Invalid Taxonomy'));
return $error;
}
}
$in_taxonomies = "'" . implode("', '", $taxonomies) . "'";
$defaults = array('orderby' => 'name', 'order' => 'ASC', 'hide_empty' => true, 'exclude' => array(), 'exclude_tree' => array(), 'include' => array(), 'number' => '', 'fields' => 'all', 'slug' => '', 'parent' => '', 'hierarchical' => true, 'child_of' => 0, 'get' => '', 'name__like' => '', 'pad_counts' => false, 'offset' => '', 'search' => '', 'limit_days' => 0, 'category' => 0, 'min_usage' => 0, 'st_name__like' => '');
$args = wp_parse_args($args, $defaults);
// Translate selection order
$args['orderby'] = self::compatOldOrder($args['selectionby'], 'orderby');
$args['order'] = self::compatOldOrder($args['selection'], 'order');
$args['number'] = absint($args['number']);
$args['offset'] = absint($args['offset']);
$args['limit_days'] = absint($args['limit_days']);
$args['min_usage'] = absint($args['min_usage']);
if (!$single_taxonomy || !is_taxonomy_hierarchical($taxonomies[0]) || '' !== $args['parent']) {
$args['child_of'] = 0;
$args['hierarchical'] = false;
$args['pad_counts'] = false;
}
if ('all' == $args['get']) {
$args['child_of'] = 0;
$args['hide_empty'] = 0;
$args['hierarchical'] = false;
$args['pad_counts'] = false;
}
extract($args, EXTR_SKIP);
if ($child_of) {
$hierarchy = _get_term_hierarchy($taxonomies[0]);
if (!isset($hierarchy[$child_of])) {
return $empty_array;
}
}
if ($parent) {
$hierarchy = _get_term_hierarchy($taxonomies[0]);
if (!isset($hierarchy[$parent])) {
return $empty_array;
}
}
// $args can be whatever, only use the args defined in defaults to compute the key
$filter_key = has_filter('list_terms_exclusions') ? serialize($GLOBALS['wp_filter']['list_terms_exclusions']) : '';
$key = md5(serialize(compact(array_keys($defaults))) . serialize($taxonomies) . $filter_key);
$last_changed = wp_cache_get('last_changed', 's-terms');
if (!$last_changed) {
$last_changed = time();
wp_cache_set('last_changed', $last_changed, 's-terms');
}
$cache_key = "get_terms:{$key}:{$last_changed}";
$cache = wp_cache_get($cache_key, 's-terms');
if (false !== $cache) {
$cache = apply_filters('get_terms', $cache, $taxonomies, $args);
return $cache;
}
$_orderby = strtolower($orderby);
if ('count' == $_orderby) {
$orderby = 'tt.count';
}
if ('random' == $_orderby) {
$orderby = 'RAND()';
} else {
if ('name' == $_orderby) {
$orderby = 't.name';
} else {
if ('slug' == $_orderby) {
$orderby = 't.slug';
} else {
if ('term_group' == $_orderby) {
$orderby = 't.term_group';
} elseif (empty($_orderby) || 'id' == $_orderby) {
$orderby = 't.term_id';
}
}
}
}
$orderby = apply_filters('get_terms_orderby', $orderby, $args);
if (!empty($orderby)) {
$orderby = "ORDER BY {$orderby}";
} else {
//.........这里部分代码省略.........
示例11: Categories_box
private static function Categories_box(&$data, $parent = 0, $level = 0, $categories = 0)
{
if (!$categories) {
$categories = get_categories(array('hide_empty' => 0));
}
if (function_exists('_get_category_hierarchy')) {
$children = _get_category_hierarchy();
} elseif (function_exists('_get_term_hierarchy')) {
$children = _get_term_hierarchy('category');
} else {
$children = array();
}
if ($categories) {
ob_start();
foreach ($categories as $category) {
if ($category->parent == $parent) {
echo "\t" . self::_wpe_edit_cat_row($category, $level, $data);
if (isset($children[$category->term_id])) {
self::Categories_box($data, $category->term_id, $level + 1, $categories);
}
}
}
$output = ob_get_contents();
ob_end_clean();
echo $output;
} else {
return false;
}
}
示例12: cherry_plugin_import_end
function cherry_plugin_import_end()
{
wp_cache_flush();
foreach (get_taxonomies() as $tax) {
delete_option("{$tax}_children");
_get_term_hierarchy($tax);
}
wp_defer_term_counting(false);
wp_defer_comment_counting(false);
update_option('cherry_sample_data', 1);
cherry_plugin_set_to_draft('hello-world');
cherry_plugin_set_to_draft('sample-page');
settings();
do_action('cherry_plugin_import_end');
session_name("import_xml");
session_destroy();
exit('import_json');
}
示例13: display_rows_or_placeholder
function display_rows_or_placeholder()
{
global $taxonomy;
$args = wp_parse_args($this->callback_args, array('page' => 1, 'number' => 20, 'search' => '', 'hide_empty' => 0));
extract($args, EXTR_SKIP);
$args['offset'] = $offset = ($page - 1) * $number;
// convert it to table rows
$out = '';
$count = 0;
$terms = array();
if (is_taxonomy_hierarchical($taxonomy) && !isset($orderby)) {
// We'll need the full set of terms then.
$args['number'] = $args['offset'] = 0;
$terms = get_terms($taxonomy, $args);
if (!empty($search)) {
// Ignore children on searches.
$children = array();
} else {
$children = _get_term_hierarchy($taxonomy);
}
// Some funky recursion to get the job done( Paging & parents mainly ) is contained within, Skip it for non-hierarchical taxonomies for performance sake
$out .= $this->_rows($taxonomy, $terms, $children, $offset, $number, $count);
} else {
$terms = get_terms($taxonomy, $args);
foreach ($terms as $term) {
$out .= $this->single_row($term, 0, $taxonomy);
}
$count = $number;
// Only displaying a single page.
}
if (empty($terms)) {
list($columns, $hidden) = $this->get_column_info();
echo '<tr class="no-items"><td class="colspanchange" colspan="' . $this->get_column_count() . '">';
$this->no_items();
echo '</td></tr>';
} else {
echo $out;
}
}
开发者ID:Esleelkartea,项目名称:herramienta_para_autodiagnostico_ADEADA,代码行数:39,代码来源:class-wp-terms-list-table.php
示例14: _pad_term_counts
/**
* Add count of children to parent count.
*
* Recalculates term counts by including items from child terms. Assumes all
* relevant children are already in the $terms argument.
*
* @access private
* @since 2.3.0
*
* @global wpdb $wpdb WordPress database abstraction object.
*
* @param array $terms List of term IDs, passed by reference.
* @param string $taxonomy Term context.
*/
function _pad_term_counts(&$terms, $taxonomy)
{
global $wpdb;
// This function only works for hierarchical taxonomies like post categories.
if (!is_taxonomy_hierarchical($taxonomy)) {
return;
}
$term_hier = _get_term_hierarchy($taxonomy);
if (empty($term_hier)) {
return;
}
$term_items = array();
$terms_by_id = array();
$term_ids = array();
foreach ((array) $terms as $key => $term) {
$terms_by_id[$term->term_id] =& $terms[$key];
$term_ids[$term->term_taxonomy_id] = $term->term_id;
}
// Get the object and term ids and stick them in a lookup table.
$tax_obj = get_taxonomy($taxonomy);
$object_types = esc_sql($tax_obj->object_type);
$results = $wpdb->get_results("SELECT object_id, term_taxonomy_id FROM {$wpdb->term_relationships} INNER JOIN {$wpdb->posts} ON object_id = ID WHERE term_taxonomy_id IN (" . implode(',', array_keys($term_ids)) . ") AND post_type IN ('" . implode("', '", $object_types) . "') AND post_status = 'publish'");
foreach ($results as $row) {
$id = $term_ids[$row->term_taxonomy_id];
$term_items[$id][$row->object_id] = isset($term_items[$id][$row->object_id]) ? ++$term_items[$id][$row->object_id] : 1;
}
// Touch every ancestor's lookup row for each post in each term.
foreach ($term_ids as $term_id) {
$child = $term_id;
$ancestors = array();
while (!empty($terms_by_id[$child]) && ($parent = $terms_by_id[$child]->parent)) {
$ancestors[] = $child;
if (!empty($term_items[$term_id])) {
foreach ($term_items[$term_id] as $item_id => $touches) {
$term_items[$parent][$item_id] = isset($term_items[$parent][$item_id]) ? ++$term_items[$parent][$item_id] : 1;
}
}
$child = $parent;
if (in_array($parent, $ancestors)) {
break;
}
}
}
// Transfer the touched cells.
foreach ((array) $term_items as $id => $items) {
if (isset($terms_by_id[$id])) {
$terms_by_id[$id]->count = count($items);
}
}
}
示例15: getTerms
/**
* Extended get_terms function support
* - Limit category
* - Limit days
* - Selection restrict
* - Min usage
*
* @param string|array $taxonomies
* @param string $args
* @return array
*/
function getTerms( $taxonomies, $args = '', $skip_cache = false, $internal_st = false ) {
global $wpdb;
$empty_array = array();
$single_taxonomy = false;
if ( !is_array($taxonomies) ) {
$single_taxonomy = true;
$taxonomies = array($taxonomies);
}
foreach ( $taxonomies as $taxonomy ) {
if ( ! is_taxonomy($taxonomy) ) {
return new WP_Error('invalid_taxonomy', __('Invalid Taxonomy'));
}
}
$in_taxonomies = "'" . implode("', '", $taxonomies) . "'";
$defaults = array(
'orderby' => 'name',
'order' => 'ASC',
'cloud_selection' => 'count-desc',
'hide_empty' => true,
'exclude' => '',
'include' => '',
'number' => '',
'fields' => 'all',
'slug' => '',
'parent' => '',
'hierarchical' => true,
'child_of' => 0,
'get' => '',
'name__like' => '',
'st_name_like' => '',
'pad_counts' => false,
'offset' => '',
'search' => '',
'limit_days' => 0,
'category' => 0,
'min_usage' => 0
);
$args = wp_parse_args( $args, $defaults );
if ( $internal_st != true ) { // Allow limit :)
$args['number'] = absint( $args['number'] );
}
$args['offset'] = absint( $args['offset'] );
if ( !$single_taxonomy || !is_taxonomy_hierarchical($taxonomies[0]) || '' != $args['parent'] ) {
$args['child_of'] = 0;
$args['hierarchical'] = false;
$args['pad_counts'] = false;
}
if ( 'all' == $args['get'] ) {
$args['child_of'] = 0;
$args['hide_empty'] = 0;
$args['hierarchical'] = false;
$args['pad_counts'] = false;
}
extract($args, EXTR_SKIP);
if ( $child_of ) {
$hierarchy = _get_term_hierarchy($taxonomies[0]);
if ( !isset($hierarchy[$child_of]) )
return $empty_array;
}
if ( $parent ) {
$hierarchy = _get_term_hierarchy($taxonomies[0]);
if ( !isset($hierarchy[$parent]) )
return $empty_array;
}
if ( $skip_cache != true ) {
// $args can be whatever, only use the args defined in defaults to compute the key
$filter_key = ( has_filter('list_terms_exclusions') ) ? serialize($GLOBALS['wp_filter']['list_terms_exclusions']) : '';
$key = md5( serialize( compact(array_keys($defaults)) ) . serialize( $taxonomies ) . $filter_key );
$last_changed = wp_cache_get('last_changed', 'terms');
if ( !$last_changed ) {
$last_changed = time();
wp_cache_set('last_changed', $last_changed, 'terms');
}
$cache_key = "get_terms:$key:$last_changed";
if ( $cache = wp_cache_get( $cache_key, 'terms' ) ) {
$terms = apply_filters('get_terms', $cache, $taxonomies, $args);
return $terms;
}
}
//.........这里部分代码省略.........