sourcecode

워드프레스에서 상위 카테고리 ID별로 하위 카테고리를 얻는 방법

copyscript 2023. 2. 11. 09:30
반응형

워드프레스에서 상위 카테고리 ID별로 하위 카테고리를 얻는 방법

제발, 누가 나를 도와줄 수 있나요, 나는 워드프레스 세계에 처음입니다.워드프레스에서 상위 카테고리 ID별로 하위 카테고리를 얻는 방법

를 사용해야 합니다.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의 차이는 부모가 부모 용어의 직계 자녀만 얻는 경우(즉, 1레벨 아래), child_of는 모든 하위 자녀(사용 가능한 수준 수)입니다.

Codex: get_terms

다음은 특정 부모로부터 자식 범주를 가져오는 가장 간단한 방법입니다.

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

언급URL : https://stackoverflow.com/questions/22443352/how-to-get-sub-categories-by-parent-category-id-in-wordpress

반응형