Skip to content

Instantly share code, notes, and snippets.

@1naveengiri
Last active March 28, 2017 08:14
Show Gist options
  • Save 1naveengiri/4fa9d9dbca621a09e6cf4a8ff783490f to your computer and use it in GitHub Desktop.
Save 1naveengiri/4fa9d9dbca621a09e6cf4a8ff783490f to your computer and use it in GitHub Desktop.
Exclude rtMedia Uplaoded media form backend media tab
<?php
/**
* Function will exclude all rtMedia uploaded media from backend media tab.
*/
function show_only_allowed_media( $query ) {
global $wpdb, $pagenow;
if ( $query->is_admin ) {
if('upload.php' === $pagenow || ( !empty($_REQUEST['action']) && 'query-attachments' === $_REQUEST['action']) ){
$wp_rt_rtm_media = $wpdb->prefix."rt_rtm_media";
$custom_query = "select media_id from ".$wp_rt_rtm_media;
// Get all rtMedia media Ids.
$results = $wpdb->get_results($custom_query,ARRAY_A);
$rtmedia_media_ids = array();
if(!empty($results)){
foreach ($results as $key => $value) {
$rtmedia_media_ids[] = $value['media_id'];
}
$query->set('post__not_in', $rtmedia_media_ids );
}
}
}
return $query;
}
add_filter('pre_get_posts', 'show_only_allowed_media');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment