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?

  • 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

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']) {

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;

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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