我使用插件类型并需要显示所有父母及其子女,但目前我只能提取父信息,而不是孩子。
父母后期类型为投资,且子项为投资更新
For example:
+ parent post
child post
child post
+ parent post
child post
我的代码:
<?php
$args = array(
'numberposts' => -1,
'order' => 'DES',
'post_type' => 'investment',
);
$query = get_posts($args);
foreach($query as $post){
echo '<li>' . get_the_title($post->ID) . '</li>';
echo '<br><br>';
//children
$child_posts = get_posts(array(
'numberposts' => -1,
'orderby' => 'name',
'post_type' => 'investment-updates',
'post_parent' => $post->ID
));
foreach ($child_posts as $child_post){
echo '<li>' . get_the_title($child_post->ID) . '</li>';
}
}
?>