Skip to content

Instantly share code, notes, and snippets.

@JoshRiser
Last active January 14, 2016 16:12
Show Gist options
  • Save JoshRiser/2f587f1298abe612c04e to your computer and use it in GitHub Desktop.
Save JoshRiser/2f587f1298abe612c04e to your computer and use it in GitHub Desktop.
Include uploaded media in the link search from TinyMCE
function fo_alter_link_query_arg($query){
$query['post_status'] = array('inherit', 'publish');
return $query;
}
function fo_alter_link_query($results){
if(empty($results))
return $results;
foreach ($results as $id => $p) {
$post = get_post($p['ID']);
if('attachment' == $post->post_type) {
$results[$id]['permalink'] = wp_get_attachment_url($post->ID);
}
}
return $results;
}
add_filter('wp_link_query_args', 'fo_alter_link_query_arg');
add_filter('wp_link_query', 'fo_alter_link_query');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment