I am trying to fetch all direct children of a page. But I am getting all children and grand children as well. Any ideas?
PHP Source:
$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 );
}
My $args
should be correct according to the documentation, but it's totally ignoring parent
and hierarchical
.
My page structure is as follows:
Parent
-Child 1
-Child 2
--Child 1 to child 2
--Child 2 to child 2
-Child 3
And I only want to get child 1
, child 2
and child 3
.
depth
option also. another solution which I found and seems to be working is$mypages = get_pages('child_of='.$post->ID.'&sort_column=post_date&sort_order=desc&parent='.$post->ID);
here you can changesort_column
&sort_order
as per need.depth
didn't help me at all, settingchild_of
andparent
to the same it was.