johnbillion/extended-cpts

filter by taxonomy when setup admin_filters key

limogin opened this issue · 4 comments

I'm unable to filter by taxonomy, I don't understand why. I have setup some as this:

'admin_filters' => array(
'genre' => array(
'title' => 'Genre',
'taxonomy' => 'genre',
),
),

but I don't see also in the query string this taxonomy as parameter.

Can you post your complete post type and taxonomy registration code?

    $labels = array(
      'name' => __('Artwork'),
      'singular_name' => __('Artwork'),
      'add_new' => __('Add New'),
      'add_new_item' => __('Add New Artwork'),
      'edit' => __( 'Edit' ),
      'edit_item' => __('Edit Artwork'),
      'new_item' => __('New Artwork'),
      'all_items' => __('All Artworks'),
      'view_item' => __('View Artwork'),
      'search_items' => __('Search Artwork'),
      'not_found' => __('No Artworks found'),
      'not_found_in_trash' => __('No Artworks found in the Trash'),
      'parent_item_colon' => '',
      'menu_name' => __('Artworks')
    );

    $args = array(
      'labels' => $labels,
      'description' => __( 'Artworks collection' ),
      'hierarchical' => false,
      'supports' => array('title', 'thumbnail', 'editor', 'page-attributes'),
      'rewrite' => array('slug' => __('artwork'), 'with_front' => true),
      'public' => true,
      'publicly_queryable' => true,
      'exclude_from_search' => false,
      'show_ui' => true,
      'show_in_menu' => true,
      'show_in_nav_menus' => false,
      'show_in_feed' => true,
      //'menu_position' => 20,
      'query_var' => true,
      'has_archive' => false,
      'can_export' => true,
      'capability_type' => 'page',
      'menu_icon' => 'dashicons-format-image',
      'admin_cols' => array (
        'featured_image' => [
				  'title'          => __('Image'),
				  'featured_image' => 'thumbnail'
			  ],
        'date' => [
				   'title_icon'  => 'dashicons-calendar-alt',
				   'date_format' => 'd/m/Y'
			   ],
        'artwork_category' => [
           'title' => __('Category'),
           'taxonomy' => 'artwork_category',
         ],
        'menu_order' => [
 				   'title' => __('Position'),
           'post_field'=>'menu_order',
 			   ],
       ),
       'admin_filters' => array(
         'artwork_category' => [
           'title' => __('Category'),
           'taxonomy' => 'artwork_category',
         ],
	 	   ),
    );

    register_extended_post_type ('artwork', $args);

I think that the issue is related why the get_taxonomy (https://developer.wordpress.org/reference/functions/get_taxonomy/) method don't return any value in the "query_var" attribute.

Then the "wp_dropdown_categories ( .." call (https://developer.wordpress.org/reference/functions/wp_dropdown_categories/) in PostTypeAdmin class, line 307 don't have any value in the name attribute.

Ok, identified the issue. The param "query_var" when is declared in register_extended_taxonomy must be set to true.