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 Slug / Page Slug Conflict – Prevent use of reserved slug on page save?
- Setting a custom sub-path for blog without using pages?
- Custom Post Type as Page parent
- Post formats “audio” and “video” only showing in index.php
- Ordering Posts List By Taxonomy Terms?
- How to add a post from a custom post type as the static page?
- Creating a Custom Post Type for Inserting Preset Content into Post & Pages?
- Add a Template to a custom post type
- WordPress calls archive page instead of Custom Page Template
- How do I Make a custom post type get a custom post template in a plugin
- Dynamic page.php template for custom post types
- Custom Posts on Different Pages
- Pagination with custom loop
- Include images from pages in wp search.php results in default wp search
- Priority for Categories, Tags, Taxonomies, Posts, Pages and Custom Posts with same url
- Pagination on a custom page template
- Multiple templates for custom post type
- How to make an archive page displaying posts in a date range
- Display Posts of a Category in Alphabetical Order (Custom Post Type)
- Make custom post type display as a page
- Child page in custom post throws 404 page not found
- CPT: archive-cpt.php VS custom page template
- Is it possible to use pages to apply static content to each taxonomy level?
- Take Variables Set in Functions.php and Echo Them Inside My Custom Post Template
- ‘Pages’ widget alternative for custom post types?
- Including Custom Post Type posts in a page template contextually (or should I widget?)
- Editable content on a Custom Archive page
- Troubles with making a custom template for posts
- Disable featured image
- Change archive page template using pre_get_post
- Custom-Posttype & Custom Taxonomy WP_Query
- Page template with different page and post content
- redirect automatic page that serves custom posttype content
- No Permission to add new Page, Post or CPT with Admin role
- Creating a Page Template to display all items from a Custom Post Type
- Filter widget outputs
- Custom Post Type Template Alternative
- General advice on addressing content-centric pages
- Fields for different parts of a page
- How do you create a custom template to display a category with an image and related posts below?
- Pages Become “Archive” Instead of Using Page Template
- How can I set the page template of a new custom post type post?
- 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?
- Custom URL redirect in WP
- WordPress Picks Up Wrong Template for Custom Post Type Archive Page
- Associate page w/ specific single post template?
- Can I change my post type to anything and my site still work?
- Page listing Custom Posts
- get comments by current user inside page template
- Why are some of my custom posts not showing up on my page?
- Hide Status Option From WordPress Publish Metabox and Rename Published on:
- Custom page for editing custom post type on frontend based on url
- How to set the mainpage of a custom post type?
- How do I display child post types in the parent post type template
- Custom permalink structure for remote content pages
- Setting a homepage – doesn’t seem to work
- wp_dropdown_pages with tax_query clause
- Am I mixing up the concept of posts pages and categories?
- Tag template not returning posts [closed]
- Does “Custom Post Type” can have page hierarhy option?
- Display custom post type from template
- 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 change Elementor Template for Single Page Post on Load
- A certain theme is forcing it’s singular post layout
- How do I find out which (page) template file my custom child post is looking for?
- Metabox collapsed by default
- How can I use one instance of page.php to display different custom post types?
- How to make “single post” permalink maintain it’s sub-page structure
- Custom post type option page template
- Custom post Query and WordPress Post Query Clash
- How to display a custom post as a page (but unedited)?
- How can I find out what template is my custom post type using?
- Search custom post type result in same template page
- Include images from pages in wp search.php results in default wp search
- Custom post type , page template not grabbing the page template
- WordPress Contents Migration
- Use the page picker from wordpress menu creation page
- custom post type archive slug vs. custom page template
- How to create a custom template for this custom post type?
- Nested custom post types templating
- archive.php can’t find categorized posts
- How to divide posts (custom post type) content on multiple pages?
- Custom Post Type Slug / Page Slug Conflict – Prevent use of reserved slug on page save?
- Page that ‘subscribes’ to multiple categories
- Page template anomaly
- How do I hide single category post on my post page
- How to add a regular page under a custom post type?
- display related posts based on the PAGE TITLE
- An script/Plugin for automatic page creation per term