Support » Fixing WordPress » Taxonomy Filter on Admin Area

  • Hello Friends,
    I have added this code to the function.php to show admin filter but when I chose any tax still send me to show all tax. so what is wrong with the below code, please.

    add_action('restrict_manage_posts', 'product_type_filter');
    function product_type_filter() {
     global $typenow;
     $post_type = 'accommodations';
     $taxonomy = 'events-categories';
     if ($typenow == $post_type) {
     $selected = isset($_GET[$taxonomy]) ? $_GET[$taxonomy] : '';
     $info_taxonomy = get_taxonomy($taxonomy);
     'show_option_all' => __("Show All {$info_taxonomy->label}"),
     'taxonomy' => $taxonomy,
     'name' => $taxonomy,
     'orderby' => 'name',
     'selected' => $selected,
     'value_field' => 'slug',
     'show_count' => true,
     'hide_empty' => true,
    • This topic was modified 2 years, 10 months ago by Canada WebMaster.
    • This topic was modified 2 years, 10 months ago by bcworkz. Reason: code fixed

    The page I need help with: [log in to see the link]

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hello,

    I’ve run your code and switched out the Custom Post Type & Taxonomy variables with my project specific types and your code ran and worked as expected. Are you sure that the Post Type and Taxonomy slugs you have in your code are the correct ones with no misspellings? For reference here’s the cleaned up code:

    function product_type_filter() {
    	global $typenow;
    	$post_type	= 'cpt_listings';	// My Custom Post Type
    	$taxonomy	= 'tax_states';		// My Custom Taxonomy
    	if( $post_type == $typenow ) {
    		$selected		= isset( $_GET[ $taxonomy ] ) ? $_GET[ $taxonomy ] : '';
    		$info_taxonomy	= get_taxonomy( $taxonomy );
    		wp_dropdown_categories( array(
    			'show_option_all'	=> esc_html__( "Show All {$info_taxonomy->label}" ),
    			'taxonomy'			=> $taxonomy,
    			'name'				=> $taxonomy,
    			'orderby'			=> 'name',
    			'selected'			=> $selected,
    			'value_field'		=> 'slug',
    			'show_count'		=> true,
    			'hide_empty'		=> true,
    		) );
    add_action( 'restrict_manage_posts', 'product_type_filter' );
    Thread Starter Canada WebMaster


    Thank you Howdy

    Yes, and the filter showing but no functions, when filter any to get back the same all posts from all tax. not sure what is going on, I disabled all the plugins still the same, is that something with JetEngine?


    Is the code you’re testing any different than the above in any way? You could use pre_get_posts hook, look for the $_GET variable and add a tax_query if it exists but you shouldn’t need to.

    Thread Starter Canada WebMaster


    can you help with full code, please?

    many thanks

    Thread Starter Canada WebMaster


    also how if I need more than 1 post type?

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Taxonomy Filter on Admin Area’ is closed to new replies.