这应该行得通。我不完全确定你的代码到底出了什么问题(已经很晚了),但下面的代码对我来说很有用。显然我换了$order->get_id()
具有已知ID和post_type
已设置为page
.
<?php
$parentid = $order->get_id();
$child = new WP_Query( array(\'post_parent\' => $parentid, \'post_type\' => \'shop_subscription\') );
if ($child->have_posts()) : while ($child->have_posts()) : $child->the_post();
$childid = get_the_ID();
endwhile;
else:
$childid = "not set";
endif;
wp_reset_query();
?>