What you need is to register your own Rewrite Rule. To do it you should use add_rewrite_rule
function.
function my_custom_external_rewrite_rule() {
add_rewrite_rule('^post-type-name/([^/]+)/?', 'index.php?page_id=<PAGE_ID>&external_page_name=$matches[1]', 'top');
}
add_action( 'init', 'my_custom_external_rewrite_rule' );
And you’ll have to register your custom query variable (using query_vars
hook):
function my_custom_external_query_var( $query_vars ) {
$query_vars[] = 'external_page_name';
return $query_vars;
}
add_filter( 'query_vars', 'my_custom_external_query_var' );
This way requests to post-type-name/slug/
will cause displaying page with and you will be able to obtain the slug of external post with get_query_var( 'external_page_name' );
Related Posts:
- Custom Rewrite with Query vars
- How to Modify Existing Rewrite Rules?
- how to add rewrite rule to wordpress default post type
- Custom query var rewriting with only variable
- Redirect Uploads Folder to Query Vars in WordPress
- Pretty Filter URL
- Add additional URL variations for a Post
- Need help with add_rewrite_rule
- remove “index.php” from permalinks
- Rewrite Rule for Multilingual Website, Like qTranslate?
- Custom post type permalink endpoint
- permalink independent on the post’s name stored in the database
- How to add a custom URL placeholder to author archives?
- URL Rewrite + Page + Custom Post Type = Unusual Redirect
- Make post slug have priority over category slug
- How to add query parameters to all internal links?
- Using two permalinks for one post
- flexible rewrite ‘ramble’ URLs with WordPress
- Permalinks for WooCommerce Categories and Subcategories
- Change the custom post type permalink
- Redirect short-form URL to long-form URL (post_id to post_id + post_name)
- Custom rewrite rules for feeds of custom queries (query_var query strings in URL)?
- Rewrite url / permalink for default archive – yearly / monthly
- Rewriting permalinks with custom posts
- Child pages with same slug
- Permalinks, Rewrites, Get Variables, Oh My!
- Change permalink for a single post entry
- Rewrite URL Parameter And Force ‘Pretty’ Permalink
- rewrite_rule for custom post type doesn’t affect get_permalink
- Add ‘articles’ prefix before blog posts url without affecting pagination
- How to get wordpress link to fully evaluate when coming from facebook
- Page Attachment Permalink Structure based on Menu Order?
- When is it a good idea to build a permalink structure from scratch?
- WordPress not respecting template hierarchy (fetches index.php instead of single.php or page.php)
- Call to a member function add_rule() on a non-object
- Permalinks: Page Not Found
- Rewrite rule to prettify two $_GET variables while in a new endpoint from a page
- Re-write specific custom post type category URL to go to another page
- How to add_rewrite_rule with two parameters to a single view page?
- RewriteRule accepts numbers but not letters in tag
- Remove custom taxonomy base from URL
- Custom Permalink
- remove sub-category of Custom Post Type from permalink structure
- Is a permastruct possible on pages?
- Rewrite rule for a query string
- How do I add /blog/ as a prefix to permalink structure for posts, categories & tags?
- Share same Slug for a Custom Post Type and 2 Taxonomies
- How to remove specific category from URL in WordPress
- Custom permalink for specific category
- Custom permalink leads to index page
- Rewrite rule intended for CPTs gives 404 for pages
- Rewrite URLs for LeadPages due to subdirectory installation
- Permalink structure between 2 custom post types and a taxonomy
- Rewriting single post url; add_rewrite_rule problem?
- How to change “attachment_id” in attachment permarlink?
- Custom rewrite rule ignored
- How to test custom rewrite rules /permalinks?
- wordpress how to replace url /bar with foo/bar for custom post type
- Remove some rewrite rules in wordpress
- Getting back a permalink from custom url
- Order custom post type posts by custom field with pretty URL
- Adding URL prefix for foreign language support
- add_rewrite_rule on default post type
- Exclude single page from permalink rule
- help to remove last trailing slash using add_rewrite_rule
- add_rewrite_rule – Page Slug from “/foo-bar/” to “/foo/bar/”
- Rewrite rule not passing variable
- permalink and add_rewrite_rule – error 404
- Rewrite Post URL so it is constructed from parent post url & child post url
- corrupted URLs – can’t leave starting page
- rewrite based slug standar post wp
- Adding custom query var to a single post without redirecting to its root slug
- Create different permalinks for same post
- remove SLASH on single_post but KEEP on categories and parent pages
- Multiple Taxonomy Items for Separate URLs
- WordPress keeps removing query var from the URL
- Fire a code when permalinks updated
- Flush rewrite rules with scheduled event (cron)
- Multiple URL rewrite rules and get every prams
- Using a template file for a specific custom URL
- Redirect page to homepage, keeping URL
- Added a prefix in URL permalink structure but the old structure still working!
- Permalinks Question: Adding a prefix ONLY in front of all posts with the ‘video’ post format
- Create new URL structure for custom post types
- How to change the URL using rewrite rule in wordpress
- No Ones Been Able to Override my WordPress Rewrite Rule Issue!
- a way to support totally different url structure
- create user’s view profile link with username
- WordPress Pagination Custom Rewrite Rule for Pages
- rewrites and custom links in page need help with add_rewrite_rule
- Add Custom Pagination Permalink
- Prevent guessing slug
- Pretty Permalink for Search Queries Not Working
- ReWrite Permalink to New Permalink Nginx
- Permalink broken for pages after adding rewrite rule
- standard post with extra parameter brings permalink problem
- Custom rewrites for pages and categories
- WordPress custom permalinks, pages are now 404
- Standard Htaccess directives disappear by themselves
- ‘Unsupported Operand Types’ error stemming from taxonomy re-writes with PHP 8.1