I need to display two levels of a custom post type posts in alpha order -- while maintaining the parent/child hierarchy. Here's my existing code:
<select class="form-select filter-select" name="..." aria-label="...">
<?php $post_type = get_posts( array(
'post_type' => 'custom-post-type',
'numberposts' => -1,
'orderby' => 'title',
'order' => 'ASC'
) );
if ( $post_type ) {
foreach ( $post_type as $post ) :
setup_postdata( $post ); ?>
<option value=".<?php print $post->post_name; ?>"><?php if ( $post->post_parent) { ?> - <?php } ?><?php the_title(); ?></option>
<?php
endforeach;
wp_reset_postdata();
} ?>
</select>
This will display the posts in alpha order -- but the child posts aren't properly displaying under their parent post. How can I address this?
UPDATE: This is for a standard Wordpress site. Not WooCommerce.
Thank you for your help.