Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

When I click to insert/edit link in the tinyMCE rich editor for a post, then click "Or link to existing content", it shows only posts that are live and published. Is there a way to get the list that is searched to also include future and draft posts? I need to do this without modifying any core files, is there a hook I can tap into to modify the called query?

share|improve this question
    
If you publish a post with a link to an unpublished post in it you will generate 404s. I think that is the logic behind tinyMCE code. I will peek at that code though and see if there is a way to change it (without editing core files). –  s_ha_dum Oct 17 '12 at 17:06
    
Yeah, I understand why they have it that way. We launch a lot of articles around a magazine issue, and it all goes live on one day –  Macgyver Oct 17 '12 at 18:25
    
Actually, it would be useful for me too and for the same reason, so I am looking into it. It would make our editors happy. So far, I have not solved it though. –  s_ha_dum Oct 17 '12 at 18:30

1 Answer 1

See if this doesn't do it:

First, the callback for that Ajax search (the wp_link_query method in wp-includes/class-wp-editor.php) suppresses the normal filters. We have to turn them back on for this particular query.

function undo_suppress($qry) {
  global $_POST;
  if (isset($_POST['action']) && 'wp-link-ajax' == $_POST['action']) {
    $qry->set('suppress_filters',false);
  }
}
add_action('pre_get_posts','undo_suppress');

Now we can use the posts_where filter to enable searches across 'future' posts.

function search_future_editor_links($where) {
  global $_POST;
  if (isset($_POST['action']) && 'wp-link-ajax' == $_POST['action']) {
    $where = ' AND wp_posts.post_type IN ("post","page","attachment") AND wp_posts.post_status IN ("publish","future") ';
  }
  return $where;
}
add_filter('posts_where','search_future_editor_links');

You could add "drafts" to that last IN if you wanted to search those too.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.