Skip to content

Instantly share code, notes, and snippets.

@DenisLeblanc
Created June 17, 2014 23:29
Show Gist options
  • Save DenisLeblanc/905df17b8882952b034b to your computer and use it in GitHub Desktop.
Save DenisLeblanc/905df17b8882952b034b to your computer and use it in GitHub Desktop.
Filter Posts by Post Format
<?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