adding a filter to post_link to link to ‘draft’ posts
-
I know that I’m going against the grain here a bit, but I’ve got a blog where I author several (5-15) posts for a couple week long camping adventure, and I often want to link between those posts before I actually publish them.
Of course, I want the links to continue to work after publishing, and I never change the titles once I’m done writing – they just sit in draft state until I publish.
I was hoping that I could hook the post_link filter so that I could use the “insert hyperlink search” functionality in TinyMCE at author time – the UI where you click the insert link button, and start typing search terms to bring up the relevant posts/pages, and choose one that you want to link to.
The code I’ve got to do this in my functions.php is as follows:
function draft_permalink( $post) { if (in_array($post->post_status, array('draft', 'pending', 'auto-draft'))) { $my_post = clone $post; $my_post->post_status = 'published'; $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(); } return $permalink; } function get_draft_permalink( $url, $post, $leavename=false ) { if ( $post->post_status == 'draft' ) $url = draft_permalink($post); return $url; } add_filter( 'post_link', 'get_draft_permalink', 10, 3 );However, I’m not seeing any of my draft posts show up in the list when I type terms in their names.
Am I missing something simple?
Thanks!
The topic ‘adding a filter to post_link to link to ‘draft’ posts’ is closed to new replies.