返回介绍

get_category_children()

发布于 2017-09-10 22:58:05 字数 2628 浏览 1118 评论 0 收藏 0

Warning: This function has been deprecated. Use get_term_children() instead.

get_category_children( int $id,  string $before = '/',  string $after = '',  array $visited = array() )

Retrieve category children list separated before and after the term IDs.


description


参数

$id

(int) (Required) Category ID to retrieve children.

$before

(string) (Optional) Prepend before category term ID.

Default value: '/'

$after

(string) (Optional) Append after category term ID.

Default value: ''

$visited

(array) (Optional) Category Term IDs that have already been added.

Default value: array()


返回值

(string)


源代码

File: wp-includes/deprecated.php

function get_category_children( $id, $before = '/', $after = '', $visited = array() ) {
	_deprecated_function( __FUNCTION__, '2.8.0', 'get_term_children()' );
	if ( 0 == $id )
		return '';

	$chain = '';
	/** TODO: consult hierarchy */
	$cat_ids = get_all_category_ids();
	foreach ( (array) $cat_ids as $cat_id ) {
		if ( $cat_id == $id )
			continue;

		$category = get_category( $cat_id );
		if ( is_wp_error( $category ) )
			return $category;
		if ( $category->parent == $id && !in_array( $category->term_id, $visited ) ) {
			$visited[] = $category->term_id;
			$chain .= $before.$category->term_id.$after;
			$chain .= get_category_children( $category->term_id, $before, $after );
		}
	}
	return $chain;
}

更新日志

Versiondescription
2.8.0Use get_term_children()
1.2.0Introduced.

相关函数

Uses

  • wp-includes/deprecated.php: get_category_children()
  • wp-includes/deprecated.php: get_all_category_ids()
  • wp-includes/category.php: get_category()
  • wp-includes/functions.php: _deprecated_function()
  • wp-includes/load.php: is_wp_error()

Used By

  • wp-includes/deprecated.php: get_category_children()

User Contributed Notes

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文