Fetching a custom WordPress Menu with Custom Post Types
<?php
$html = '';
// Get all Child Pages
$args_1 = array(
'post_status' => 'publish',
'post_type' => 'custom_post_type_1',
'orderby' => 'title',
'order' => 'ASC',
'suppress_filters' => false,
);
$query_1 = new WP_Query( $args_1 );
$posts_1 = $query_1->posts;
$args_2 = array(
'post_status' => 'publish',
'post_type' => 'custom_post_type_2',
'orderby' => 'title',
'order' => 'ASC',
'suppress_filters' => false,
);
$query_2 = new WP_Query( $args_2 );
$posts_2 = $query_2->posts;
$_posts_merged = array_merge( $posts_1, $posts_2 );
$_posts_ids = array();
foreach ( $_posts as $key => $value ) {
array_push( $_posts_ids, $value->ID );
}
$comma_separated_post_ids = implode(',', $_posts_ids); // We do this because of WPML
$args_list_pages = array(
'echo' => false,
'include' => $comma_separated_post_ids,
'title_li' => '',
'suppress_filters' => false,
);
$html .= '<ul>';
$html .= wp_list_pages( $args_list_pages );
$html .= '</ul>';