Created
November 10, 2016 15:08
-
-
Save gagimilicevic/69d3af1504ef18a876b86db300c0357b to your computer and use it in GitHub Desktop.
Custom Post Type Filter Admin By Custom Taxonomy
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
add_action('restrict_manage_posts', 'dm_filter_post_type_by_taxonomy'); | |
function dm_filter_post_type_by_taxonomy() { | |
global $typenow; | |
$post_type = 'faq'; // change to your post type | |
$taxonomy = 'faqs_category'; // change to your taxonomy | |
if ($typenow == $post_type) { | |
$selected = isset($_GET[$taxonomy]) ? $_GET[$taxonomy] : ''; | |
$info_taxonomy = get_taxonomy($taxonomy); | |
wp_dropdown_categories(array( | |
'show_option_all' => __("Show All {$info_taxonomy->label}"), | |
'taxonomy' => $taxonomy, | |
'name' => $taxonomy, | |
'orderby' => 'name', | |
'selected' => $selected, | |
'show_count' => true, | |
'hide_empty' => true, | |
'hierarchical' => true, | |
)); | |
}; | |
} | |
add_filter('parse_query', 'dm_convert_id_to_term_in_query'); | |
function dm_convert_id_to_term_in_query($query) { | |
global $pagenow; | |
$post_type = 'faq'; // change to your post type | |
$taxonomy = 'faqs_category'; // change to your taxonomy | |
$q_vars = &$query->query_vars; | |
if ( $pagenow == 'edit.php' && isset($q_vars['post_type']) && $q_vars['post_type'] == $post_type && isset($q_vars[$taxonomy]) && is_numeric($q_vars[$taxonomy]) && $q_vars[$taxonomy] != 0 ) { | |
$term = get_term_by('id', $q_vars[$taxonomy], $taxonomy); | |
$q_vars[$taxonomy] = $term->slug; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi! I need help adapting this to work with user taxonomy, think you might help?