我需要检查下一个对象的任何子项本身是否有子项。我想用 for 循环来做,但我不知道该怎么做。
对象如下:
$children = new WP_Query(array('post_type'=>'page', 'post_parent'=>get_the_ID(), 'post_status'=>'publish','orderby'=>'menu_order','order'=>'ASC'));
先感谢您 :)
这是我的做法:
$children = get_posts(
array(
'post_type'=>'page',
'post_parent'=> get_the_ID(),
'post_status'=>'publish',
'orderby'=>'menu_order',
'order'=>'ASC'
)
);
foreach ( $children as $child ) {
$has_kids = wp_list_pages( 'echo=0&child_of=' . $child->ID );
if ($has_kids) {
echo $child->post_title . " has children.";
} else {
echo $child->post_title . " doesn't have children.";
}
}