Try this :
function change_post_type_link( $link, $post = 0 ){
if ( $post->post_type == 'questions' ){
return home_url( 'questions/'. $post->post_name ."https://wordpress.stackexchange.com/". $post->ID );
} else {
return $link;
}
}
add_action( 'init', 'change_rewrites_init' );
function change_rewrites_init(){
add_rewrite_rule(
'questions/([a-z-]+)/([0-9]+)?$',
'index.php?post_type=questions&p=$matches[1]&postid=$matches[2]',
'top' );
}
Here post slug is attached after questions
in the URL. For example questions/q-slug/45
. Rewrite rule is changed accordingly.
Related Posts:
- Custom rewrite rules for archive page and single post
- WordPress Rewrite Rules for Custom Post Type and Taxonomy
- Multiple post types – share same ReWrite slug?
- How to modify URL structures in custom post types and taxonomies or terms
- Adding meta values to permalink
- Archive page with multiple taxonomies rewrite
- Permalinks so that one custom post type appears to be a child of another, not working
- Taxonomy archives based on Custom Post Type
- Change page /2 to /transcript with a Rewrite
- Permalink rewrite with custom post type and custom taxonomy
- Prepend meta_value to permalink of post
- Rewrite custom post type url’s adding meta box values
- Multiple parameters in a custom post type url rewrite
- Permalinks for CPT breaks permalinks to pages
- Remove base slug in CPT & CT, use CT in permalink
- WordPress Rewrite rule for nested post types
- Custom Post Type rewrite redirects to homepage
- single-{post_type}.php is not loaded despite flushing rules
- Custom Permalink Tag breaks Pagination
- Adding paged query to custom URL rewrite
- Custom Post Type rewrite rules not working, how to alter the rewrite order?
- Custom Permalink for Taxonimie and Custom Post Type
- how to get archive urls with same origin for custom types and terms?
- Rewrite numeric ID parameter for hierarchical custom post type
- Customising rewrite rules for CPT single post URL to work as paged URL
- Remove custom post type slug not working for child pages
- How to Combine Two Custom Post Types into Single Permalink Structure
- Pagination problem
- Permalink Structure CPT With Custom Taxonomy Fails
- Remove url rewrites for registered taxonomies
- How to change custom post type permalink structure
- Front custom edit post page for each post
- How can I use get_post_meta with add_rewrite_rule to build custom permalinks?
- Can’t get custom rewrite tag, query var, permastruct (permalink structure), and rewrite rule to work properly together
- Rewrite Question Mark in Post Template to Make it Pretty URL
- How can achieve this permalink perfectly? domain.com/%category%/%post-name%
- Customize Custom Post Type URL
- How do I change the custom taxonomy slug to be the same as the custom post type slug?
- Custom taxonomy rewrite with query var returns %2F in URL
- WP Rewrite Rule Issue while using Custom post type & taxonomy
- Custom Permalinks with CPT and Hierarchical Taxonomies
- Rewrites/query for multiple hierarchical custom post types
- cpt and page sharing same base permalink
- Hide or disallow default custom post type url?
- Post Type rewrite rule to point to custom Page/template
- How to get list of taxonomy slugs ordered parents>childs?
- Rewrite Endpoints and CPTs – How to use in a plugin
- Permalink structure with custom taxonomies and custom post type like /parent-tax/child-tax/custom-post-type-name (with no base name)
- add_rewrite_rule and passing variables for custom post types
- Pretty URLs and custom post types
- Specific routing for CPT
- Custom Rewrite Rule for Custom Post Type with URL Param
- WordPress custom slug rewrite
- Custom Permalinks for Custom Post Types
- Postname on unique permalink structure appends “-2” for a custom post type. How can I get this to stop happening?
- Combine multiple CPT names to create valid permalinks
- Set parent for custom post type archive rewrite url
- Route subpage to Custom Post Type
- How to rewrite custom taxonomy term archive to use THE SAME SLUG/front as CPT
- Rewrite permalink for multiple post types (CPT) with taxonomy term
- WordPress custom permalink and archive link for custom post type
- How to rewrite the post slug of a custom post type post
- rewriterule not working
- Pagination for custom post types – url rewriting
- Modifying rewrite rules to use /category//
- Add Custom Values to Permalinks Through Custom Fields and Posts
- Custom Post Type Date Based Archive URL rewrite [duplicate]
- Rewrite rules for custom post type
- Custom taxonomy and post type rewrite rules
- Url Rewriting a dynamic wordpress page with parameters
- Remove cpt slug from url and use custom taxonomy instead breaks all other cpt
- multiple URLS for the same page
- Rewrite URL for CPT to domain/post-name/post-id
- How to apply multiple rewrite_rule to a single custom post type url?
- How to properly set the rewrite rules for this case?
- Custom permalink structure for custom post types including multiple taxonomy
- CPTs relationship
- Change CPT permalink to use the category
- add_rewrite_rule wordpress ignoring url pattern, wp rewrite not working
- How to fix 404 on post after prepending Custom Post Type url with Custom Taxonomy Term slug
- Custom Post Type parent/child relationship rewrite rules for permalinks
- Redirect Custom Post Type from Child Taxonomies
- Rewrite url for custom post type with specific url
- How to build overlapping custom post_type and taxonomy rewrites without conflicts?
- Two CPT: one is using part of the custom rewrite slug from the other
- Custom post type rewrite and wp_pagenavi interfering with each other
- Custom Post Type rewrite url to /category/pagetitle [duplicate]
- WordPress custom post type rewrite rule matches all pages returning 404
- page not found for example.com/custom-post-name
- Paging not working for hierarchical custom post type
- redirect old post type url to new structure url
- Archive page for a custom post type using WPML
- Why won’t this rewrite rule work?
- Parent cpt/child custom post type URL permalink relationship
- Rewrite Rule & Regex – Extract ‘cat-name’ and ‘page-number’ from http://domain.com/custom-post-type/category/cat-name/page/page-number
- rewrite rules add a folder in the path
- Custom Taxonomy in Permalink from post type
- Custom post type permalink structure
- add_rewrite_rule not working in Custom Post Type UI Plugin
- What is the best way to relate different custom post types?