Problem: I have a WYSIWYG field that includes a link button. I would like to restrict existing content links by post type.
Solution: The following code sample shows how to restrict entire post types from the existing content link menu:
// filter custom post types out of existing content link options in tinyMCE
function custom_wp_link_query_args($query)
{
$pt_new = array();
$exclude_types = array( 'book', 'chapter' );
foreach ($query['post_type'] as $pt)
{
if (in_array($pt, $exclude_types)) continue;
$pt_new[] = $pt;
}
$query['post_type'] = $pt_new;
return $query;
}
add_filter('wp_link_query_args', 'custom_wp_link_query_args');
Relevant Documentation:
https://codex.wordpress.org/Plugin_API/Filter_Reference/wp_link_query_args