問題描述
我正在尋找一個頁面的所有直接的孩子。但我也是所有的孩子和大孩子。有任何想法嗎?
PHP 來源:
$args = array(
'child_of' => $post->ID,
'parent ' => $post->ID,
'hierarchical' => 0,
'sort_column' => 'menu_order',
'sort_order' => 'asc'
);
$mypages = get_pages( $args );
foreach( $mypages as $post )
{
$post_tempalte = the_page_template_part();
get_template_part( 'content' , $post_tempalte );
}
根據 documentation,我的 $args 應該是正確的,但完全忽略 parent 和 hierarchical 。
我的頁面結構如下:
Parent
-Child 1
-Child 2
–Child 1 to child 2
–Child 2 to child 2
-Child 3
而且我只想得到 child 1,child 2 和 child 3 。
最佳解決方案
請檢查參數’parent’ 。名字後面似乎有一個空格。
參考文獻
注:本文內容整合自 Google/Baidu/Bing 輔助翻譯的英文資料結果。如果您對結果不滿意,可以加入我們改善翻譯效果:薇曉朵技術論壇。