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
- Highlighting wp_nav_menu() Ancestor Class w/o Children in Nav Structure?
- Placing a Custom Post Type Menu Above the Posts Menu Using menu_position?
- 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
- 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]
- automatically placing custom post types singles into submenu of main nav menu
- Renaming Menu Item within Admin Menu Section for a Custom Post Type?
- Problem excluding category from get_next_post
- How to Programically add to the new WordPress menus
- specify meta_key / meta_value condition for prev_post_link and next_post_link
- Full-Ajax Theme: parseJSON error while building a JSON object from a WordPress custom template
- Highlight nav menu terms
- Editor access to menu: custom post type missing
- Settings page above CPT page in admin section
- Remove current_page_parent from posts page link in WordPress nav menu
- 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
- Menu highlight custom post type archive
- How to get custom post type menu_name?
- current-menu-item not working with custom post type
- Showing Custom Content in a Nav Dropdown
- Add the current menu item CSS class to a custom page type archive in WordPress menu
- wp_nav_menu() mark current item ancestor of custom post type
- Menu Multiple Taxonomies
- how to get post slug from url in wordpress
- Twenty Fifteen: Adjacent posts by menu_order [duplicate]
- Set menu active state for custom posttype and category, given custom taxonomy term
- 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
- How to make this menu drop down or like accordion
- Custom Post Type Nav to Subpage
- Custom Post Types don’t highlight in menu nav
- Querying both pages and posts
- Using default WP menu functionality to link to custom post-type listing?
- wordpress wp_list_pages help
- Paging doesn’t work?
- Hide post navigation if current post is in a category with only one post
- How to display custom WP menus?
- Single custom post type’s menu ancestor/parent is Posts archive page
- Losing Nav Active State in Menu
- menu link to custom post_type?
- Custom Post Type & Custom Menu Walker to append custom class for active post types
- How does the ‘the_post_navigation()’ work for CPT’s?
- How can I use archive-{post_type}.php theme template?
- Custom Post Type Link added to menu won’t show in frontend
- How To Display A List Of CPT Posts In A Meta Box On Menus Page?
- Get custom post type categories to show up in menus
- Displaying Custom Posts
- Prevent custom post type from showing up in custom menus
- List All Custom Post Types Posts in Nav Menu Dynamically
- How to programmatically add elements in a custom menu
- Custom Posttype and menu classes
- Can’t Get Parent and Child Categories of Custom Taxonomy to Display
- Previous / Next Links For Custom Post Type Sorted By Meta_Value
- Include “Scheduled” (“Future”) Posts in WordPress Post Navigation ( previous_post_link, next_post_link ) for a Specific Custom Post Type
- Menu for taxonomies and posts belongs to taxonomy
- Manually adding current_page_parent to wp_list_pages()
- cpt not display inside nav menu
- current-post-parent for custom post type
- Custom post type category link + add to menu
- Adding a nav menu for a custom post type
- Insert a hash into the url of custom posts to make them function as anchors
- Post navigation doesn’t show (in custom template, custom post type, custom query)
- Custom Post Type parent slug as menu item
- current_menu_parent for custom post type and custom url
- List all posts from custom post type by taxonomy
- how to override menu widget?
- Programmatically Split A Post Into Multiple Pages
- CPT Archive with parent page
- next_posts_link returns same content of 1st page
- Setting a Master Menu on a Custom Post Type
- Show posts of parent in edit.php
- and custom post_types to custom menu
- Menu that shows months and filters posts to show only posts from that month and shows posts as sub items
- Why is Posts page selected when showing single Custom Post Type?
- Navigation links to posts in current term shortcode
- sidebar hierarchical menu category & custom post type
- get_the_post_navigation not working
- Can’t add custom post type archive page to menu