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?

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.

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *