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'; 
            '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 :

enter image description here

here what i get when i filter :

enter image description here

Thanks a lot in advance for your help :)

3 Answers 3


For the sorting, you are missing how you want to sort it.


'order' => 'ASC'


'order' => 'DESC'
  • Sorry maybe i didn't explained well, what i mean is i add a dropdown list with the taxonomy on my custom post dislay list, when i select a taxonomy and click filter to list only the post with this taxonomy, there is always zero result when im sure there is and in the dropdown list i have the number (x) aside of each taxonomy.
    – Christophe
    Mar 10, 2015 at 7:54

You should use the action hook pre_get_posts which WordPress uses to set up the entire query.

add_action('pre_get_posts', function($query) {

    // do not exectute if outside admin
    if( !is_admin() )

    // only do stuff to the main query
    if( !$query->is_main_query() )

    // only execture on post type
    if( get_current_screen()->post_type !== 'student' )

    // no need to filter if not our taxonomy
    if( !isset($_REQUEST['activity']) )

    $query->set('tax_query', array(
            'taxonomy'      => 'activity',
            'field'         => 'term_id',
            'terms'         => $_REQUEST['activity'],
  • I tried added it but it didnt change it i still get no results when filter :/
    – Christophe
    Mar 10, 2015 at 10:30
  • What i don't get is why is it working on my local installation and note the online one...
    – Christophe
    Mar 10, 2015 at 10:40

If it works localy, Disable the plugins installed on production website to rule out a conflict with those. You can use this plugin to test disabling them without disturbing users of the website if it is live


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.