• i created a custom post type and also some taxonomy to be able to perform sorting on the display list.

    It is all working well on my local testing installation but as soon as i put on the production website (where there is some other plugins etc installed compared to my local), then the sorting is not working anymore, any idea ?

    Here some part of the plugin code related to my taxonomy and custom post type :

    add_action('init', 'students_init');
    function students_init(){
    
        $labels = array(
            'name' => 'Students',
            'singular_name' => 'Student',
            'add_new' => 'Add a student',
            'add_new_item' => 'Add a new student',
            'edit_item' => 'Edit a student',
            'new_item' => 'New student',
            'view_item' => 'See the student',
            'search_items' => 'Search a student',
            'not_found' => 'No students',
            'not_found_in_trash' => 'No students in the trash',
            'parent_item_colon' => '',
            'menu_name' => 'Students',
        );
    
        register_post_type('student', array(
            'public' => true,
            'publicly_queryable' => false,
            'labels' => $labels,
            'menu_position' => 2,
            'capability_type' => 'post',
            'supports' => false,
        ));
    
        //add_image_size('slider', 1000, 300, true);
    
        register_taxonomy( 'activity', 'student', array( 'hierarchical' => true, 'label' => 'Activity', 'query_var' => true, 'rewrite' => true, 'show_admin_column' => true, ) );
    
    }
    
    add_action( 'restrict_manage_posts', 'students_restrict_manage_posts' );
    function students_restrict_manage_posts() {
        global $typenow;
    
        if ( $typenow == 'student' )
        {
    
            $taxonomy = 'activity';
            wp_dropdown_categories(array(
                'show_option_all' =>  'Voir toutes les catégories',
                'taxonomy'        =>  $taxonomy,
                'name'            =>  $taxonomy,
                'orderby'         =>  'name',
                'selected'        =>  $_GET[$taxonomy],
                'hierarchical'    =>  true,
                'show_count'      =>  true,
                'hide_empty'      =>  true
            ));
        }
    }
    
    add_action( 'request', 'students_admin_request' );
    function students_admin_request( $request ) {
    
        if ( is_admin() && isset( $request['post_type'] ) && $request['post_type'] == 'student' )
        {
            $taxonomy = 'activity';
            $request[$taxonomy] = get_term_by( 'id', $request[$taxonomy], $taxonomy)->slug;
    
        }
        return $request;
    }

    Here what i have :

    Screenshot 1

    here what i get when i filter :

    Screenshot 2

  • The topic ‘Custom post type taxonomy not filtering correctly’ is closed to new replies.