简体   繁体   English

如何在wordpress中按父类别ID获取子类别?

[英]how to get sub categories by parent category id in wordpress?

please, can any one help me , I am new in wordpress world. 拜托,任何人都可以帮助我,我是wordpress世界的新手。 how to get sub categories by parent category id in wordpress? 如何在wordpress中按父类别ID获取子类别?

You need to use get_terms($taxonomies, $args); 你需要使用get_terms($taxonomies, $args);

$parent_term_id = 4; // term id of parent term (edited missing semi colon)

$taxonomies = array( 
    'category',
);

$args = array(
    'parent'         => $parent_term_id,
    // 'child_of'      => $parent_term_id, 
); 

$terms = get_terms($taxonomies, $args);

You could also use 'child_of' instead; 您也可以使用'child_of'代替;

Note: the difference between child_of and parent is that where parent only gets direct children of the parent term (ie: 1 level down), child_of gets all descendants (as many levels as are available) 注意:child_of和parent之间的区别在于,父级只能获得父级术语的直接子级(即:1级向下),child_of获取所有后代(可用的级别)

Codex: get_terms Codex: get_terms

Here is the Simplest way to get child category from specific parent 以下是从特定父级获取子类别的最简单方法

$parent_id = 12;
$termchildren = get_terms('product_cat',array('child_of' => $parent_id));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM