Last active
January 14, 2016 16:12
-
-
Save JoshRiser/2f587f1298abe612c04e to your computer and use it in GitHub Desktop.
Include uploaded media in the link search from TinyMCE
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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