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
- Is there a way to establish parent/child relationship in WP menu links exclusively?
- Use custom walker to add taxonomy terms to main nav menu
- A page that shows a list of a specific custom post type
- Single custom post type’s menu ancestor/parent is Posts archive page
- Losing Nav Active State in Menu
- menu link to custom post_type?
- Review site custom post type structure
- Custom Post Type & Custom Menu Walker to append custom class for active post types
- Ordering Submenu Pages in WP 3.1
- 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?
- 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
- How can I create an automatic drop down menu with my tags?
- show current item in custom menu, when inside a custom post type
- WordPress menu with custom taxonomy
- Displaying Custom Posts
- Prevent custom post type from showing up in custom menus
- List All Custom Post Types Posts in Nav Menu Dynamically
- Custom Post Type – Portfolio no longer works
- How to programmatically add elements in a custom menu
- New posts label category with “new”
- Custom Posttype and menu classes
- 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()
- Can’t Get Parent and Child Categories of Custom Taxonomy to Display
- Home page is getting current-menu-item even if it’s not home
- Placing Admin Post Metaboxes in Tabs
- 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
- 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?
- Manually adding current_page_parent to wp_list_pages()
- build child and anchestor three from post parent
- Prev/Next Navigation on Single Post Disappeared for Custom Post Type
- wordpress get menu id by custom post_type?
- cpt not display inside nav menu
- wp_get_nav_menu_items doesn’t return custom post type item
- current-post-parent for custom post type
- Automatically add CPT UI categories to the menu
- 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
- Possition a Custom Post Type Tab under Settings
- Post navigation doesn’t show (in custom template, custom post type, custom query)
- how to display notifications in the wordpress menu when a new post is published
- Menu disappears with custom post type link
- Use the page picker from wordpress menu creation page
- How to display custom post type in a submenu?
- Custom Post Type parent slug as menu item
- current_menu_parent for custom post type and custom url
- add current-menu-item to multiple custom post types
- 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?
- Custom Taxonomy Showing in WP Menu
- Programmatically Split A Post Into Multiple Pages
- Plugins for putting Custom Post Types into the Menu
- 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
- CPT Archive with parent page
- Getting (Invalid) when adding custom taxonomy of custom post type link in menu [closed]
- next_posts_link returns same content of 1st page
- Custom post type navigation – 404 on page 2
- 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
- How to make a single Menu Item call another Mega Menu for Custom Post Types and Custom Taxonomies?
- Highlight specific menu item when custom post is page
- sidebar hierarchical menu category & custom post type
- Pagination for Custom Post Type with Multiple Types
- Menu Structure and URL structure, with Pages and Post-Type-Posts
- get_the_post_navigation not working
- Can’t add custom post type archive page to menu
- How to build help pages similar to WordPress Developer Resources
- Trying to add CPT to menu automatically
- custom post type dynamically shows in menubar in wordpress