OK, I think I have cracked it. The below code seems to work well. To be able to use a custom post type I added an argument into the $args array'post_type' => 'product',
Is the below OK?
<div id="sub-pages">
<?php
global $post;
$args = array(
'post_type' => 'product',
'child_of' => get_top_ancestor_id(),
'title_li' => ''
);
$the_query = new WP_Query($args);
?>
<ul>
<?php wp_list_pages($args); ?>
</ul>
<?php wp_reset_postdata(); ?>
</div>
// Get top ancestor
function get_top_ancestor_id() {
global $post;
if ($post->post_parent) {
$ancestors = array_reverse(get_post_ancestors($post->ID));
return $ancestors[0];
}
return $post->ID;
}
Related Posts:
- Remove current_page_parent nav class from blog index when in CPT
- Why are navigation items saved in the database?
- adding .current* tags to custom post types and taxonomies
- Add/Remove current_page_parent class
- Custom Post Types in the WordPress Navigation Menu
- How can i automatically add CPT single pages as sub menu items
- Navigation not working for custom post type pages
- wp_nav_menu doesn’t seem to work on custom post type pages
- Custom nav menu current item custom link problem
- Calling the first & last post by category in custom post type
- current_page_item and custom post type?
- Navigation won’t update to show full path to single post
- Placing a Custom Post Type Menu Above the Posts Menu Using menu_position?
- Adding an Archive of Posts to the Navigation Menu in WordPress 3.0
- Adding custom post type archives to a WordPress menu
- How to add custom post type archive page links to nav menu?
- Creating “static” taxonomies to choose from, inside custom post type?
- Query menu_order custom post types
- How to add meta box to backend menu page
- Custom Post Type Menus
- How make get_next_post() return first post when viewing last one
- How can I get my Custom Post Types to appear in nav-menus.php ‘Menu’?
- Highlighting current item of custom post types’ sub pages, listed by wp_list_pages
- Extend walker class with custom post types [closed]
- Hide custom post type from nav menu manager
- automatically placing custom post types singles into submenu of main nav menu
- How to Programically add to the new WordPress menus
- specify meta_key / meta_value condition for prev_post_link and next_post_link
- Menu with Automatic Pages Included from Custom Post Type
- Full-Ajax Theme: parseJSON error while building a JSON object from a WordPress custom template
- Editor access to menu: custom post type missing
- Custom Post Type .current-menu-item not applying on Custom Post Type Archive Page
- Highlight parent menu item when child post
- Select menu should display categories and the item’s depth
- wordpress custom post type remove duplicate menu item
- Adding Custom Taxonomy Archive Link to Nav Menu Shows Up As (Invalid)
- Menu highlight custom post type archive
- How to get custom post type menu_name?
- wp_get_nav_menu_items wp-admin/customize.php problem
- How do I create an archive page for standard posts?
- current-menu-item not working with custom post type
- Showing Custom Content in a Nav Dropdown
- wp_nav_menu() mark current item ancestor of custom post type
- current-menu-item class for custom post type parent
- Menu Multiple Taxonomies
- how to get post slug from url in wordpress
- Fake mark a menu item as current_page_item/active in WordPress
- Twenty Fifteen: Adjacent posts by menu_order [duplicate]
- Update menu when saving settings
- custom post type not showing in menu
- Correct classes for WordPress menu items
- Custom Taxonomy Navigation, with current menu items for children?
- Customize the Dashboard Menu Editor
- Display posts from Custom Post Type in category page on front-end
- Use menus with anchors
- Custom Post Type Nav to Subpage
- Custom Post Types don’t highlight in menu nav
- Querying both pages and posts
- Showing up my custom post type in primary navigation
- Paging doesn’t work?
- Hide post navigation if current post is in a category with only one post
- page menu entry for custom post type
- Use custom walker to add taxonomy terms to main nav menu
- menu link to custom post_type?
- Review site custom post type structure
- Including link to custom post type in ‘wp_list_pages’ function
- Which Template Page Should I Use?
- How does the ‘the_post_navigation()’ work for CPT’s?
- WordPress menu with custom taxonomy
- highlight parent page menu item when in custom post type
- Custom post type post in custom menu
- Custom post type posts wont show in wp_nav_menu()
- Home page is getting current-menu-item even if it’s not home
- Previous / Next Links For Custom Post Type Sorted By Meta_Value
- Menu for taxonomies and posts belongs to taxonomy
- How to get next post link of child custom post type from parent post and get next post link of parent post from the last child post?
- How can I put content before my custom post type default pages?
- How we can create menu from Appearance > Menu and use as a add-submenu-page for admin menu?
- wp_get_nav_menu_items doesn’t return custom post type item
- Automatically add CPT UI categories to the menu
- Insert a hash into the url of custom posts to make them function as anchors
- Possition a Custom Post Type Tab under Settings
- how to display notifications in the wordpress menu when a new post is published
- Menu disappears with custom post type link
- How to display custom post type in a submenu?
- List all posts from custom post type by taxonomy
- Nav style for current page with custom post type
- Admin menu post type
- How to display the FAQ Archive page in my menu
- how to override menu widget?
- No Current Class showing in Menu for Custom Post Types
- Custom post type in submenu with custom meta box as a title with custom html
- Getting (Invalid) when adding custom taxonomy of custom post type link in menu [closed]
- Custom post type navigation – 404 on page 2
- Show posts of parent in edit.php
- Highlight specific menu item when custom post is page
- sidebar hierarchical menu category & custom post type
- Pagination for Custom Post Type with Multiple Types
- get_the_post_navigation not working
- Can’t add custom post type archive page to menu