Filter Media by attached page or blog post in Library

I am trying to create a filter using restrict_manage_posts that will filter all media according the page or post type that have been attached to. Actually i need to create a filter that refers to the Uploaded to column. I have been trying many variations with no luck.

function media_add_uploaded_to_dropdown()
{
    $scr = get_current_screen();
    if ( $scr-base !== 'upload' ) return;

    $attached_page = filter_input(INPUT_GET, 'attached_page', FILTER_SANITIZE_STRING );
    $selected = (int)$attached_page  0 ? $attached_page : '-1';
    $args = array(
        'show_option_none'   = 'All Pages',
        'name'               = 'attached_page',
        'selected'           = $selected
    );
    wp_dropdown_users( $args );
}
add_action('restrict_manage_posts', 'media_add_uploaded_to_dropdown');

Any help would be appreciated.

Topic media-library post-type uploads filters hooks Wordpress

Category Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.