Last active
August 29, 2015 14:03
-
-
Save javierarques/7c2aefd911884d000327 to your computer and use it in GitHub Desktop.
CUSTOM ADMIN FILTER: Add taxonomy filter to wp-admin posts listing
This file contains hidden or 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
/************************************************************************************** | |
* CUSTOM ADMIN FILTER | |
* Add taxonomy filter to wp-admin posts listing | |
**************************************************************************************/ | |
add_action( 'restrict_manage_posts', 'my_restrict_manage_posts' ); | |
function my_restrict_manage_posts() { | |
global $typenow; | |
wp_dropdown_categories( array( | |
'taxonomy' => 'ciudad', | |
'hide_empty' => false, | |
'hierarchical' => 1, | |
'show_option_all' => __('Filtrar por guía', THEME_DOMAIN), | |
'walker' => new Walker_TaxonomyDropdown, | |
'orderby' => 'name', | |
'id' => 'select-location', | |
'name' => 'ciudad' | |
)); | |
if ( $typenow === 'negocio') { | |
wp_dropdown_categories( array( | |
'taxonomy' => 'categoria', | |
'hide_empty' => false, | |
'hierarchical' => 1, | |
'show_option_all' => __('Tipo de Negocio', THEME_DOMAIN), | |
'walker' => new Walker_TaxonomyDropdown, | |
'orderby' => 'name', | |
'id' => 'select-location', | |
'name' => 'categoria' | |
)); | |
} | |
} |
This file contains hidden or 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
/** | |
* Create HTML dropdown list of Categories. | |
* | |
* @package WordPress | |
* @since 2.1.0 | |
* @uses Walker | |
*/ | |
class Walker_TaxonomyDropdown extends Walker_CategoryDropdown { | |
/** | |
* @see Walker::$tree_type | |
* @since 2.1.0 | |
* @var string | |
*/ | |
var $tree_type = 'category'; | |
/** | |
* @see Walker::$db_fields | |
* @since 2.1.0 | |
* @todo Decouple this | |
* @var array | |
*/ | |
var $db_fields = array ('parent' => 'parent', 'id' => 'term_id'); | |
/** | |
* Start the element output. | |
* | |
* @see Walker::start_el() | |
* @since 2.1.0 | |
* | |
* @param string $output Passed by reference. Used to append additional content. | |
* @param object $category Category data object. | |
* @param int $depth Depth of category. Used for padding. | |
* @param array $args Uses 'selected' and 'show_count' keys, if they exist. @see wp_dropdown_categories() | |
*/ | |
function start_el( &$output, $category, $depth = 0, $args = array(), $id = 0 ) { | |
$pad = str_repeat(' ', $depth * 3); | |
/** This filter is documented in wp-includes/category-template.php */ | |
$cat_name = apply_filters( 'list_cats', $category->name, $category ); | |
//$cat_permalink = get_term_link( $category ); | |
$cat_permalink = add_query_arg($category->taxonomy, $category->slug); | |
$output .= "\t<option data-permalink=\"".$cat_permalink."\" class=\"level-$depth\" value=\"".$category->slug."\""; | |
if ( $category->term_id == $args['selected'] ) | |
$output .= ' selected="selected"'; | |
$output .= '>'; | |
$output .= $pad.$cat_name; | |
if ( $args['show_count'] ) | |
$output .= ' ('. number_format_i18n( $category->count ) .')'; | |
$output .= "</option>\n"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment