This is a little “hacky”, but when you call get_permalink
and you need the permalink for a draft, provide a clone of your post object with the details filled in:
global $post;
if ( in_array( $post->post_status, array( 'draft', 'pending', 'auto-draft' ) ) ) {
$my_post = clone $post;
$my_post->post_status="publish";
$my_post->post_name = sanitize_title(
$my_post->post_name ? $my_post->post_name : $my_post->post_title,
$my_post->ID
);
$permalink = get_permalink( $my_post );
} else {
$permalink = get_permalink();
}
Related Posts:
- How to make draft posts or posts in review accessible via full url / slug?
- Create slugs programmatically
- wp_publish_post to saved draft, permalinks broken
- My permalinks are broken! Can I use mod_rewrite to ignore a physical file?
- When creating a WordPress page, a “-2” suffix is added to new pages’ permalinks
- mod_rewrite enabled but Permalinks show index.php
- Why does /wp-json/ not work on the “plain” permalink structure?
- Custom Permalink: /year/month/post-goes-here/?
- Turn off %postname% auto-incrementing?
- How to get the post id from a permalink?
- Does a parent page’s post_title have to appear in a child page permalink?
- Enable Minify in W3Total Cache using NGINX [closed]
- Stop redirecting to posts not in a category / duplicate slugs
- How to make variables in URL look like the permalink structure?
- Why I can’t change the permalink of this page?
- Custom Taxonomy URL
- WordPress not respecting template hierarchy (fetches index.php instead of single.php or page.php)
- Why does chrome keep downloading a file instead of running the site?
- How can I add a page’s ID to its permalink using WP_Rewrite?
- Re-write specific custom post type category URL to go to another page
- Get page by path – honoring permalink settings (urls w/slashes)
- How to change the permalink option to post name on theme activation?
- Does rename of page slugs create 301 redirects from old slug to new (same as for posts)?
- Changing post content on save, using updated fields
- Change in permalink structure made javascript cookie not work correctly
- Change permalinks on move from one site to another
- Making permalinks to /%postname%/ by default in installation
- Share same Slug for a Custom Post Type and 2 Taxonomies
- Custom Post Type Yearly Archive Permalinks
- Images in media library have suddenly disappeared
- Post with Custom Permalinks
- Can’t select blog month within archive category
- Passing the JQuery string to Worldpress URL
- An other permalink problem – 404 Error
- permalink results to “page not found”
- permalinks issue and archives
- How to prevent WP overwriting my custom htaccess rewrites?
- WordPress basic functions show on top in custom shortcode
- Internal linking when on a shared IP
- Edit permalink for certain pages
- How can I include permalinks in this code?
- How can I redirect this contact form to a specific permalink
- Strange behavior with a redirect loop – involves WPML multi-language plugin
- Adding category slug to posts permalink causes 404 error
- http: not showing in wordpress permalink setting
- Apply function only if end of url has /amp/ [closed]
- Post Title to link to a PDF
- Permalinks – .htaccess
- Configuring Home Page Address
- Combine category AND custom taxonomy in permalink structure
- How to Force HTTPS on a WordPress and remove HTTPS from permalinks
- permalink and add_rewrite_rule – error 404
- Permalinks that go to a specific template
- WP-e-commerce (getshopped) – Annoying permalink issue [closed]
- IIS7.5 URL rewrite pboblem on index page
- Pages show 404 error instead of homepage
- Category blog URL 404
- Rewrite Post URL so it is constructed from parent post url & child post url
- Redirect to brand page after click on the brand logo
- Permalinks (don’t kill me) refuses to work..Yes, it results in a 404
- Read more block is appending /#more-{post_id} to the link
- URL getting changed
- Create different permalinks for same post
- WordPress /page/2 gives 404 when custom permalinks is set to %category%%postname%
- Cannot make custom search permalink to work in a fully custom theme. Search string $_GET[‘s’] is always empty
- Redirect old /%category%/%postname%/ to just /%postname%/
- Why does one of my pages not have the option to edit the link?
- Giving specific category posts its own permalink structure returns 404
- Flushing rewrite rules enables to see an article, but I didnt change anything
- Changing link format from Calendar widget
- Permalink length
- How can I put WordPress in a directory but keep just the home page at the domain root?
- while changing permalink, page redirected you too many times
- WordPress – Permalink custom Structure – 404
- I noticed only on 2 pages I keep getting permalimks changed with added -2 or -3?
- Change permalink structure ONLY for new posts
- swedish charater åäö in permalinks
- Change permalinks of ‘post’ type (add_rewrite_rule or ?????)
- Internationalize Forum Posts Without Translating Them
- how to get Pretty permalinks($wp_rewrite) till `INIT` action?
- Where is wordpress redirecting wp-admin/admin/dashboard to wp-admin and how to turn it off
- “post-name” Renders Using page.php, but “post-name-2” renders with single.php
- Why is this “blog” keyword automatically added in permalink settings?
- 403 Forbidden Error on subdomain
- How to structure a wordpress site in folders?
- Search page Paginations not working
- Used wordpress built-in permalink to change post url but the page is not found
- How to remove .html permalink without every post getting 404?
- Only homepage working correctly, 404 error on everything else
- wp_unique_post_slug is not unique
- Removed and Reinstalled WordPress, Redirect Broken now
- Pretty links for PHP pages above WP /blog directory?
- Text in permalink
- custom permlink .htaccess file 404 Not Found error
- Why are all pages redirecting to homepage when using custom permalinks?
- After I migrated a website for WordPress – Saved changes in wordpress settings >> permalinks. Homepage only working, links not working
- Single product link in woocomerce
- Parent pages not found with pretty permalinks
- Support Gallery link to pages
- URL issues with WordPress