Custom posts filters in admin

I create a custom type post and categories for them. I tried to make filters for this custom type posts. But it doesn’t work. I don’t know what is wrong in my code

add_action( 'init', 'create_carte_post_type' );
function create_carte_post_type() {
  register_post_type( 'carte',
    array(
      'labels' => array(
        'name' => __( 'La carte' ),
        'singular_name' => __( 'Produit' ),
        'all_items'  => __( 'Tous les produits' ),
        'add_new_item' => __( 'Ajouter un produit'),
        'add_new'  => __( 'Ajouter un produit' ),

      ),
        'publicly_queryable' => true,
        'show_ui' => true,
        'query_var' => true,
        'menu_icon'   => get_stylesheet_directory_uri() .'/framework/produit.svg',
        'rewrite' => true,
        'capability_type' => 'post',
        'hierarchical' => true,
        'menu_position' => 5,
        'taxonomies' => array('carte'),
        'supports' => array('title','editor','thumbnail')
    )
  );
}

add_action('restrict_manage_posts','filtres');

function filtres() {
            global $typenow;

            if ($typenow=='carte'){
                         $args = array(
                             'show_option_all' => "Show All Categories",
                             'taxonomy'        => 'carte-category',
                             'name'               => 'carte-category',

                         );
                wp_dropdown_categories($args);
                        }
        }
add_action( 'request', 'requestTx' );
function requestTx($request) {
    if (is_admin() && $GLOBALS['PHP_SELF'] == '/wp-admin/edit.php' && isset($request['post_type']) && $request['post_type']=='carte') {
        $request['term'] = get_term($request['carte-category'],'carte-category')->name;

    }
    return $request;
}

function taxo() {

    register_taxonomy(
        'carte-category',
        'carte',
        array(
            'label' => __( 'Type de produits' ),
            'rewrite' => array( 'slug' => 'la-carte' ),
            'hierarchical' => true,
        )
    );
}
add_action( 'init', 'taxo' );

The filters dropdown is showing in the page

enter image description here

but filters don’t work.
enter image description here

If someone could help 🙂

0

Leave a Comment