• Hi there

    I want to add a combo box that will allow me to filter the media by the page/post it is attached to.

    The idea is to have this combo in the media library page, just like the filter by date combo box.

    thanks in advance

Viewing 1 replies (of 1 total)
  • This is how we did it

    add_action('admin_head-media-upload-popup','wmg_add_my_media_button');
    function wmg_add_my_media_button(){
    	 $args = array(
    	'numberposts'   	=> -1,
        'orderby'         => 'title',
        'order'           => 'ASC',
        'post_type'       => array('post','page'),
        'post_status'     => 'publish' );
    
    	$posts_array = get_posts( $args ); 
    
    	if($_GET['tab']=='library'){
    		add_filter('pre_get_posts','wmg_my_search_filter');
    
    		function wmg_my_search_filter($wp_query) {
    			$wp_query->query_vars['post_parent'] = $_GET['filter_post'];
    			return $wp_query;
    		}
    	}
    	?>
    
    	<script type="text/javascript" >
    		jQuery(document).ready(function(){
    			jQuery('select[name=m]').after(	"<select name='filter_post' style='width: 93px;'><option value='' selected='selected'>-??? ????-</option><?php foreach($posts_array as $one_post){
    		echo "<option value=".$one_post->ID.">".addslashes($one_post->post_title)."</option>";
    	}?></select>");
    		});
    	</script>
    
    	<?php
    }
    ?>
    <style>
    #media-upload .tablenav .tablenav-pages{
    	width: 190px;
    }
    </style>
Viewing 1 replies (of 1 total)
  • The topic ‘filter media by page/post it is attached’ is closed to new replies.