Here is a simple solution, if post have DRAFT status – we show a “normal” do not rewrited “URL”.
add_filter( 'post_type_link', 'custom_post_permalink' ); // for cpt post_type_link (rather than post_link)
function custom_post_permalink ( $post_link ) {
global $post;
$type = get_post_type( $post->ID );
$post_status = get_post_status( $post->ID ); //get POST STATUS
if($post_status != "draft") {
return home_url('PUT YOUR CUSTOM POST TYPE HERE/'.$post->post_name.'.html');
} else {
//if POST STATUS is DRAFT
return home_url('?post_type=PUT YOUR CUSTOM POST TYPE HERE&p='.$post->ID.'&preview=true');
}
}
Related Posts:
- Can a custom post type have a Parent Page?
- Rewriting a custom-post-type permalink with taxonomy term?
- Custom Post Type Permalink / Rewrite not working immediately
- How to remove /blog/ prefix for custom post types in permalinks?
- WordPress Custom Post Type is Matching on Partial Slug
- Change slug of registered custom post type in child theme
- Templates for Custom Post Types and Custom Taxonomies
- How to achieve this permalink -> category-name/custom-post-type-name/post-name
- Custom permalinks
- Permalink for CPT with taxonomy
- Custom post type permalink changing itself every other change
- Add links to post categories and taxonomies in wysiwyg link modal?
- Custom post type’s get_permalink returns wrong url
- ACF Relationships in Custom Post Type Permalink
- Prepend meta_value to permalink of post
- Custom Permalinks for Custom Post Types and Taxonomies
- Removing parent slug from URL on custom post type
- URL rewrite and navigation structure for wordpress custom post type
- Maintaining WP_Query Relation Among CPT, Custom Taxonomy, Permalinks- CPT UI
- Custom post type category, taxonomy and URL rewrite problem
- Rewrite on custom post type permalink not working?
- Remove taxonomy slug when not assigning taxonomy with custom post types
- Custom Post Type: How to display all of same taxonomy?
- Custom post type permalink missing /post_type/ front
- Remove POST_TYPE from custom post type permalink
- Remove “-2” from a Toolset Types URL with the same post name
- Add extra parameters after permalink?
- Custom post types and permalink
- custom post type default permalink
- How to create a permalink structure with custom taxonomies and custom post types like base-name/parent-tax/child-tax/custom-post-type-name
- Custom post types, taxonomies, and permalinks
- How to specify URLS for custom posts & taxonomies
- How do I get the permalink structure to work like this?
- Permalinks not working for custom taxonomy on custom post type
- Custom Post Type permalink shows wrong page: homepage/index.php
- Get term name and term parent into custom post type permalink
- Rewrite rules for custom posts types
- Does WordPress consider a post name unique if that same post name is in multiple Post Types?
- Adding custom post category slug in permalink causes 404 error for pages and posts
- How can I use get_post_meta with add_rewrite_rule to build custom permalinks?
- How to set a CPT to have a page as a parent, then rewrite urls accordingly?
- Custom post type as home page with custom url
- URL rewrite add author as base
- Change custom post type permalink to show name of post from another custom post type?
- Parent Page and Breadcrumb URL’s for Custom Post Types Not Working
- CPT’s with landing page instead of archive – Url Rewrite?
- Hierarchical permalinks for custom post type and taxonomy
- How to organize hierarchical structure in custom post type with taxonomy (like with categories)
- Custom Post Type – Duplicate Page Slugs
- Remove permalink for custom post type
- Best way to specify “article type” in URL
- How to have permalink like domain.com/term/postname?
- Custom post type permalink returns 404 when set to private
- Custom post type slug 404
- How to filter a custom post type by custom taxonomy without 404
- how to retain the ability to modify the post slug after applying a post_type_link filter?
- Pagination of custom post type leads to 404 error
- Custom permalink structure for remote content pages
- WordPress Custom URLs
- Improve Custom Post Permalink Structure
- Adding an extra parameter [string] to my posts’ permalink?
- Custom Post Type nest under a normal WordPress Page
- Is it possible to have hierarchical taxonomy and hierarchical custom post types in one permalink?
- Pagination does not work on Custom Post Type archive while trying to get load more function working
- Permalinks not working (404) for the ‘item’ post type
- Wp PageNavi only works with default permalinks on a custom post type?
- Custom category URL not displaying posts
- Change permalink for custom post type?
- Use a different URL path / permalink for CPT
- Duplicate slug/permalink issue while adding same post name
- Custom post type defaults to index.php for archive page
- Permalinks: custom post type -> custom taxonomy -> custom sub taxonomy -> post
- Pretty Permalinks with CTP and Taxonomies / Hierarchical
- % encoded URL giving 404 error in WordPress
- Adding categories to custom post type in permalink
- Issue with Custom Post Types and Permalinks
- How can i remove post type archive URL?
- Custom post type URL structure with site.com/custom_taxonomy_slug/post_name
- Links Image in “Catalog” Page to Posts
- Why does my plugin require a permalink reset after a new installation?
- 404 custom post type
- How to have permalink structure based on taxonomy terms
- Custom post type permalink issue [duplicate]
- Multiple post types or single post type with category taxonomy?
- Get full control over custom post type url
- How to switch from custom post type URL to category URL?
- Custom Post Type with /%shop_name%/gallery/%gallery% permastruct?
- Customizing the custom post type permalink
- Get post id of permalink for a specific custom post type?
- Adding 2 CPT with multiple custom taxonomies to permalinks
- Custom Post Type permalink not working on new posts
- URL Rewrite Adjustment for Custom Post Type causes template to revert to index.php
- Add taxonomy to custom post type archive
- Storing postID in session variable to query database when visitor on custom template page
- Is it possible to remove the word “date” from archives?
- Custom post type – permalink
- Permalink for regular posts “/blog/”
- Permalink for Custom Post Types
- How to get taxonomy category in permalink for each taxonomy OR How to give a parent page to a given taxonomy?
- How to correctly edit permalink structures for both default and custom posts/taxonomies?