是否可以在Wordpress中循环访问特定的父母孩子?
目前,我已经研究了:
$post->post_parent == '2'
但这更像是一个 if 语句条件。我也尝试了以下方法,但我需要一个特定的父母孩子。
while(have_posts()) : the_post();
以下文章帮助了我:https://wordpress.org/support/topic/displaying-wp_list_pages-and-custom-fields
您可以使用自定义查询:
$the_query = new WP_Query(array(
'post_parent' => 2
));
while ($the_query->have_posts())
{
$the_query->the_post();
echo get_the_title();
}
wp_reset_postdata();