Add / Remove Post Type from “Link to existing content” popup

Old question but I found an answer at Here by Simon Hampel at the bottom. Cool filter, but I coulnd’t find a whole lot of documentation on it so I’m not 100% sure everything it’s connected to. One thing I do know is it’s used to pull the links on ‘Link to existing content’. Put this in your functions.php file:

function custom_wp_link_query_args($query)
{
    $pt_new = array();

    $exclude_types = array('exclude_post_types_here');

    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');

Leave a Comment