如何在WordPress中通过父类别ID获取子类别?

请, 任何人都可以帮助我, 我是wordpress世界中的新手。如何在WordPress中通过父类别ID获取子类别?


#1


你需要使用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);

你也可以使用’child_of’代替;

注意:child_of与parent的区别在于, parent仅获得父项的直接子项(即:1级下移), child_of获得所有后代(尽可能多的级别)

法典:get_terms


#2


这是从特定父母那里获得子女类别的最简单方法

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

来源:

https://www.srcmini02.com/65353.html

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_37305.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?