You can add a rewrite tag and rules that capture anything after the post name:
function wpd_add_rewrites(){
add_rewrite_tag( '%my_page%', '(.+)' );
$post_types = array(
'movie',
'book',
'album'
);
foreach( $post_types as $post_type ){
add_rewrite_rule(
'^' . $post_type . '/([^/]*)/([^/]*)/?',
'index.php?post_type=" . $post_type . "&name=$matches[1]&my_page=$matches[2]',
'top'
);
}
}
add_action( 'init', 'wpd_add_rewrites' );
Don’t forget, you must flush rewrite rules after adding / changing them. You can do this quickly by just visiting the Settings > Permalinks page.
You can then check the value of my_page
anywhere after the wp
action:
echo get_query_var( 'my_page' );
Related Posts:
- Multiple portfolios with one custom post type?
- Custom Blog Post Listing in Genesis Sample Child Theme
- Pull in custom content types into page template
- Show Custom Post Type meta boxes only on Page Edit
- Why does my content disapear when I make a page to match an archive name?
- Displaying posts inside table having issues
- Using custom post types within a section of a template
- Custom Post Type Template Alternative
- General advice on addressing content-centric pages
- Top Level pages in wordpress giving 404, but child pages working fine
- Fields for different parts of a page
- next_/previous_post_link() `in_same_category` appears to fail when true
- Multiple templates for single custom post type
- Page for custom post type
- How do you create a custom template to display a category with an image and related posts below?
- WordPress Custom Search by post_type
- Why does not this wp_redirect work in is_single()?
- Pages Become “Archive” Instead of Using Page Template
- How can I set the page template of a new custom post type post?
- Why is get_pages() returning a boolean?
- Custom post type pages return 404 page?
- Pros and cons of a custom page vs custom post type template file
- How to include custom post type posts on a page?
- Multiple single templates?
- Including link to custom post type in ‘wp_list_pages’ function
- the_content(); of custom post type treated as an array or object
- Custom URL redirect in WP
- WordPress Picks Up Wrong Template for Custom Post Type Archive Page
- Associate page w/ specific single post template?
- Multiple pages per post (not pagination)
- Can I change my post type to anything and my site still work?
- Page listing Custom Posts
- Display an authors post on a single page only when they are logged in
- Include php on a specific page template
- get comments by current user inside page template
- page template for custom post type
- Page Template Dropdown For Custom Post Types
- Why are some of my custom posts not showing up on my page?
- Merge page with custom post type
- Conflict between wp_list_pages and get_posts – list pages not displaying
- Hide Status Option From WordPress Publish Metabox and Rename Published on:
- How to integrate single and archive templates for custom post type in any WordPress theme
- providing access to post_id or post inside functions.php
- wp_get_canonical_url showing first url of the post for custom page
- Custom page for editing custom post type on frontend based on url
- Dynamic assign a custom template to custom post type posts
- URL Rewrite – Page Archive
- How to get the current category with custom posts
- How to set the mainpage of a custom post type?
- Render a Post or Page using the correct file
- How do I display child post types in the parent post type template
- How can I modify a custom post type and custom page template for a child theme if all content seams to be handled by theme’s ‘native’ plugin?
- How to add page under a custom post type?
- Custom permalink structure for remote content pages
- Enabling permalinks disables custom page template
- Setting a homepage – doesn’t seem to work
- Custom Post Type Specific Post Template
- Mixing Custom Post Types and Page Templates in WordPress 3.7.1
- Under What Conditions Can I name my CPT the same as my CPT Page?
- Custom Post Type Template Insert not working properply
- custom post creation on front page – on submit a search is done
- wp_dropdown_pages with tax_query clause
- Am I mixing up the concept of posts pages and categories?
- How to setup different permlalinks for posts and pages?
- Loop and add Specific Categories and Products Images
- custom post template ignored after altering permalinks
- Getting subpage of subpage – Custom posts
- Sets post_parent in custom post type posts automatically based on cpt->page name
- Tag template not returning posts [closed]
- Does “Custom Post Type” can have page hierarhy option?
- Custom Post Type page template doesn’t show up
- How can I allow users to edit text that will be displayed on a custom post type archive page?
- Using get_terms() to list terms from one custom taxonomy AND from one specific built-in category
- Display ONE taxonomy and its assigned pages
- Display custom post type from template
- Problem with custom loop navigation inside the blog page
- WordPress giving me the index
- How do I disable the built-in editor and automatically configure the properties of new pages?
- How to set a ‘page’ as parent of a custom post type?
- How to use pre_get_posts on archive page custom post type
- Can I automatically assign a page template to a custom post type (i.e page-slug.php file)
- How To Display Posts Of Custom Post Type At Page Template
- Virtual page and loading template
- Custom Post type dont use custom page template (slug is not right)
- How to change Elementor Template for Single Page Post on Load
- A certain theme is forcing it’s singular post layout
- How to create additional rendering for custom post types?
- Modify Custom Post Type Slug
- How do I find out which (page) template file my custom child post is looking for?
- Add custom template ‘sub-page’ to Custom Post type?
- Metabox collapsed by default
- WordPress Page hierarchy ( parent is singular of custom post types slug ) is returning not found
- How can I create a button that when clicked populates a div with a list of foods that are checked as a certain type of ACF?
- How to use posts as tabs in a custom page?
- Custom Post Type Single Page and Archive Page redirects to Home Page
- Custom post type not pulling CSS
- Set a template on a custom post in the plugin
- Create Custom page with custom domain
- How to stop a permalink redirecting to a page whit same slug but different permalink
- How can I use a custom template to load custom post type posts based on a post_meta value