2014-03-05 4 views
1

다음 함수가 배열의 모든 하위 페이지를 출력하려고합니다. 모든 것이 잘 작동한다고해서 ASC에 주문을 올려야합니다.Wordpress는 오름차순으로 자식 페이지를 가져옵니다.

$my_wp_query->query(array('post_type' => 'page')); // This gives me everything 

$my_wp_query->query(array('post_type' => 'page', 'order' => 'ASC')); // This gives me nothing 

저는 WordPress에 새로 왔으며 한 시간 동안 Google에 알려 봤지만 찾을 수 없었습니다. 누구든지 도와주세요.

감사

function get_children_pages_by_page_title($page_title = ''){ 

$my_wp_query = new WP_Query(); 

$all_wp_pages = $my_wp_query->query(array('post_type' => 'page', 'order' => 'ASC')); 



$page_title = empty($page_title) ? get_page_by_title() : $page_title; 

$portfolio = get_page_by_title($page_title); 
$portfolio_children = get_page_children($portfolio->ID, $all_wp_pages); 

return $portfolio_children; 
} 

답변

3

는 경우 다른 사람이 필요에

function get_children_pages_by_page_title($page_title = ''){ 
$page_title = empty($page_title) ? get_page_by_title() : $page_title; 
$portfolio = get_page_by_title($page_title); 
$args=array(
'child_of'=>$portfolio->ID , 
'sort_order' => 'ASC', 
'sort_column' => 'post_title', 
'post_type' => 'page', 
'post_status' => 'publish' 
); 
$portfolio_children=get_pages($args); 
return $portfolio_children; 
} 
+1

Works !!! 고맙습니다. – what

0

하고자으로 정렬하기 위해 열 'sort_column' => 'post_title'을 추가 get_pages($args)를 사용하여이 작업을 시도하십시오. 모든 페이지를 주문해야하며 아이들은 그런 식으로 주문됩니다.

$my_wp_query = new WP_Query(); 
$all_wp_pages = $my_wp_query->query(array('post_type' => 'page', 'posts_per_page' => '-1', 'orderby' => 'menu_order', 'order' => 'ASC')); 

$children_of_parent = get_page_children($parent_id, $all_wp_pages); 

foreach($children_of_parent as $child) { 
    echo $child->ID 
} 
0

왜 @emilushi의 대답에 제로 업 보트가 없는지 잘 모르겠습니다. 그냥 작동합니다. 여기

내가 사용하는 것입니다 :

$all_wp_pages = $my_wp_query->query(array('post_type' => 'page', 'posts_per_page' => '-1', 'orderby' => 'menu_order', 'order' => 'ASC')); 
       $page_parent = wp_get_post_parent_id(get_the_ID()); // Get page parent ID. Will return 0 for parent pages. 

새로운 답을 작성하는 것은 아직 언급하지 못할 // 때문이다.

+1

이것은 질문에 대한 답변을 제공하지 않으며, 코멘트 여야합니다. [언제 코멘트해야합니까?] (https://stackoverflow.com/help/privileges/comment)를 참조하십시오. [평판] (https://stackoverflow.com/help/whats-reputation)이 충분하면 모든 게시물에서 [comment] (https://stackoverflow.com/help/privileges/comment) 할 수 있습니다. 대신, [질문자의 설명이 필요없는 답변을 제공하십시오] (https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can- i-do- 대신). – Dwhitz

+0

내가 의견을 말할 수 있는지 확실하지 않았습니다. 이 일이 끝나면 내가 보게. –

관련 문제