Skip to content

Instantly share code, notes, and snippets.

@jdhobbsuk
Last active August 29, 2015 14:22
Show Gist options
  • Save jdhobbsuk/7f4291cdb3bf2cd970ff to your computer and use it in GitHub Desktop.
Save jdhobbsuk/7f4291cdb3bf2cd970ff to your computer and use it in GitHub Desktop.
Filter CPT by
// Add Hospital filter to CPTs (in admin)
// -------------------------------------------------------------
function restrict_people_by_hospital() {
global $typenow;
$taxonomy = 'hospital';
if ($typenow == 'consultant') {
$selected = isset($_GET[$taxonomy]) ? $_GET[$taxonomy] : '';
$info_taxonomy = get_taxonomy($taxonomy);
wp_dropdown_categories(array(
'show_option_all' => __("All {$info_taxonomy->label}s"),
'taxonomy' => $taxonomy,
'name' => $taxonomy,
'orderby' => 'name',
'selected' => $selected,
'show_count' => false,
'hide_empty' => true,
));
};
}
add_action('restrict_manage_posts', 'restrict_people_by_hospital');
function id_conversion_for_hospitals($query) {
global $pagenow;
$taxonomy = 'hospital';
$q_vars = &$query->query_vars;
if($q_vars['post_type'] == 'consultant'):
if ($pagenow == 'edit.php' && 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;
}
endif;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment