Created
June 17, 2014 23:29
-
-
Save DenisLeblanc/905df17b8882952b034b to your computer and use it in GitHub Desktop.
Filter Posts by Post Format
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
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' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment