我是 WordPress 新手,想獲取所有term_id = 1的子項,
下面是我的 Term Query 代碼片段,截圖中顯示了類別結構。
但是我從日志中得到的,它會顯示所有的術語。我也嘗試過“父母”,但沒有用。
(版本 WordPress 6.0)
$term_args = [
'taxonomy' => 'category',
'hide_empty' => 0,
'hierarchical' => 1,
'child_of' => 1
];
$terms = new \WP_Term_Query($term_args);
if (!is_admin()){
var_dump($terms->get_terms());
}
在此處輸入影像描述
uj5u.com熱心網友回復:
為此使用get_terms。下面的代碼獲取父項的所有子項。
$args = array(
'taxonomy' => 'category',
'hide_empty' => 0,
'hierarchical' => 1,
'child_of' => 1
);
$taxonomies = get_terms( $args );
if ( !empty( $taxonomies ) || !is_wp_error( $taxonomies ) ) {
var_dump($taxonomies);
}
它對我有用!
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/487974.html
標籤:WordPress
上一篇:如何使用條件映射二維陣列?
