Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I need to filter my posts by Post-Formats in admin ?

How can I do that ?

For now, Wordpress allows to filter by Categories and Dates.

share|improve this question

3 Answers 3

up vote 6 down vote accepted

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' );
share|improve this answer
    
Yep ! Thanks ! It WORKS perfectly except when I choose no post-format, it returns me nothing. Example : One category + no post-format = NOTHING –  Steffi Aug 16 '11 at 15:13
    
Just a note, you can actually query directly for post formats by adding &post_format=aside as an example to the URL...However!!! .. it doesn't quite work properly and generates notices/warnings, which i can only assume is a bug as it also has other side-effects(you'll see what i mean if you test it). –  t31os Aug 16 '11 at 15:28
    
@Steffi: sorry i fixed it (I think) and updated the code. –  Bainternet Aug 16 '11 at 15:51
    
Had a few problems getting the filter to work myself, you may be able to spot a fix in my code(one thing specifically had me going in circles for a while).. ;) –  t31os Aug 16 '11 at 15:56
    
@t31os, fixed and tested, code updated. –  Bainternet Aug 16 '11 at 16:42

I was actually already working on a solution for you, just had to rewrite several parts of the code(because i based it off another plugin i wrote that does the same but for page templates on hierarchal types).

This is a little bigger than Bainternet's plugin, so by all means stick to his solution if you're happy with it(don't feel obligated to switch is all i'm saying), i'm going to post it up anyway, for the sake of anyone who may be interested. It'll work for any post type that supports post formats.

Edit/Update: Decided i might aswell put the code into a proper plugin, also did the same for adding a page template filter to hierarchal post types(that support page templates). Linked below for anyone interested,

Hope that's helpful.. :)

share|improve this answer
    
NOTE: If i missed/overlooked anything, drop a comment onto the answer. –  t31os Aug 16 '11 at 15:40

A little bugfix, to keep the dropdown selection to the actual post format, in the function wpse26032_restrict_manage_posts_format :

function wpse26032_restrict_manage_posts_format()
{

    $post_format_ID = ( isset( $_GET['p_format'] ) && $_GET['p_format'] != '' ) ? $_GET['p_format'] : -1;

    wp_dropdown_categories( array(
         'taxonomy'         => 'post_format'
        ,'hide_empty'       => 0
        ,'name'             => 'p_format'
        ,'show_option_none' => 'Select Post Format'
        ,'selected'         => $post_format_ID
    ) );
}
add_action( 'restrict_manage_posts', 'wpse26032_restrict_manage_posts_format' );
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.