$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>Custom posts filters in admin|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

Custom posts filters in admin

matteradmin10PV0评论

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

but filters don't work.

If someone could help :)

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far