How to filter by post-format in admin?

Try this plugin i cooked up:

<?php
! defined( 'ABSPATH' ) AND exit;
/**
 * Plugin Name: (#26032) WP_List_Table Post Format filter extension
 * Plugin URI:  http://wordpress.stackexchange.com/questions/26032/how-to-filter-by-post-format-in-admin
 * Description: Filters the admin WP_List_Table by post format
 * Author:      Bainternet
 * Author URI: http://en.bainternet.info
 */


function wpse26032_admin_posts_filter( &$query )
{
    if ( 
        is_admin() 
        AND 'edit.php' === $GLOBALS['pagenow']
        AND isset( $_GET['p_format'] )
        AND '-1' != $_GET['p_format']
        )
    {
        $query->query_vars['tax_query'] = array( array(
             'taxonomy' => 'post_format'
            ,'field'    => 'ID'
            ,'terms'    => array( $_GET['p_format'] )
        ) );
    }
}
add_filter( 'parse_query', 'wpse26032_admin_posts_filter' );

function wpse26032_restrict_manage_posts_format()
{
    wp_dropdown_categories( array(
         'taxonomy'         => 'post_format'
        ,'hide_empty'       => 0
        ,'name'             => 'p_format'
        ,'show_option_none' => 'Select Post Format'
    ) );
}
add_action( 'restrict_manage_posts', 'wpse26032_restrict_manage_posts_format' );

Leave a Comment