我需要检查下一个对象的任何子项是否都有子项。 我想用for循环来做这件事,但我不知道该如何去做。
对象如下:
$children = new WP_Query(array('post_type'=>'page', 'post_parent'=>get_the_ID(), 'post_status'=>'publish','orderby'=>'menu_order','order'=>'ASC'));
提前谢谢你:)
答案 0 :(得分:0)
我将如何做到这一点:
$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.";
}
}