ホームページ  >  記事  >  バックエンド開発  >  wordpress ソースコード: $taxonomies[0] in exclude_tree in get_terms

wordpress ソースコード: $taxonomies[0] in exclude_tree in get_terms

WBOY
WBOYオリジナル
2016-06-23 13:15:401184ブラウズ

get_terms 中 exclude_tree 里的 $taxonomies[0]??何か么不是 $taxonomies??
@param string|array $taxonomies 分類名 または 分類名 のリスト。
@type array|string $exclude 除外する用語 ID の配列またはカンマ/スペース区切りの文字列。
$include が空でない場合、$exclude は無視されます。  デフォルトの空の配列。
@type array|string $exclude_tree 除外する用語 ID の配列またはカンマ/スペース区切りの文字列
子孫用語。 $include が空でない場合、$exclude_tree は無視されます。
デフォルトの空の配列。 
@type int $child_of 子の用語を取得するための用語ID。 複数のタクソノミーが渡された場合、$child_of は無視されます。 デフォルトは 0。
@type bool|int $hide_empty どの投稿にも割り当てられていない用語を非表示にするかどうか。 
1|true または 0|false を受け入れます。 デフォルト 1|true。
function get_terms( $taxonomyes, $args = '' )

$exclusions = array();
if ( ! empty( $exclude_tree ) ) {
$exclude_tree = wp_parse_id_list( $exclude_tree );
$excluded_children = $exclude_tree; foreach($ exclude_tree as $ runk){
$ excluded_children = array_merge(
$ excluded_children、
(array)get_terms($ taxonomies [0]、array( 'child_of' => intval($ suctunk)、 '=' = > 'ids', 'hide_empty' => 0 ) )
);                        // つまり何么这里不是 $taxonomyes??

$excludes = array_merge( $excluded_children, $exclusions );
        }

if ( ! empty( $exclude ) ) {
$exclusions = array_merge( wp_parse_id_list( $exclude ), $exclude );
}


回复讨论(解决方案)


$tax onomy_objects = get_object_taxonomyes( 'post', 'objects' );
print_r( $taxonomy_objects);

?>
配列
(
[カテゴリ] => stdClass オブジェクト
(
[階層] => 1
[update_count_callback] =>
[rewrite] =>
[query_var] => category_name
[ public] => 1
[show_ui] => 1
[show_tagcloud] => 1
1 [ラベル] => stdClass オブジェクト
(
...
)

。 ..

[名前] => カテゴリ
[ラベル] => カテゴリ
[post_tag] => stdClass オブジェクト
(
...
)

[post_format] =>stdClass オブジェクト
(
....
)

)

上で見ることができる $taxonomies[0]

上で見ることができる、 $taxonomies[0] = category
我们知道、post_tag 有 parent property方法は针对! empty( $exclude_tree ) の場合、カテゴリに対するものです。
コード者はカテゴリを直接このように調整しており、問題はありませんが、バグが存在します。 @param 文字列|配列 $taxonomies タクソノミー名 または タクソノミー名リスト 分別名または分別名列表

これで分かる $taxonomies 是文字列または数组


無判断で使用 $taxonomies[0] 是错误的!

司会者は正しいです。 Wordpress マニュアル http://codex.wordpress.org/Function_Reference/get_terms
例では:
// これらを例として使用するデフォルト値はありません
$taxonomies = array(
'post_tag',
'my_tax',
);

$args = array(
'orderby' => 'name',
'order' => 'ASC',
'hide_empty' => true,
'exclude' = > array()、
'exclude_tree' s' => 'all'、
'parent' => ''、
'hierarchical' => child_of' => 0、
'childless' => ''、
'name__like' => '、
'pad_counts' => false,
'offset' =& gt; '',
'cache_domain' => 'core'

$terms($taxonomys, $) args);
?>
$taxonomies[0]="post_tag"
--- -この場合、get_terms はパラメーターによって問題が発生しないため、引き続き機能します。
この問題が実際に存在する場合は、WordPress 開発チームに連絡してください

答えは、パラメータ child_of: $child_of Term ID の説明にあります。複数の分類法が渡された場合、$child_of は無視されます。つまり、配列 $taxonomyes には 1 つの要素しか含めることができません。

声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。