Support » Developing with WordPress » Admin Default Sorting for Custom Post Type

  • Resolved swani


    I am going crazy. I have been Googling and working on this for hours. I can’t figure out how to set my custom sort on a custom post type (in the admin area) to be ascending by title. Every post I have found uses some form of this.

    $wp_query->set('orderby', 'title');
    $wp_query->set('order', 'asc');

    I have tried changing the priority, I have added die to make sure that the function itself is running. I’ve done a var_dump() to check that the order and orberby are properly set. Nothing changes. My eventual goal is to only apply the default sort to a CPT, but I’ll settle for having my code do anything at all at this point. Any ideas on what I’m doing wrong? Thanks so much. Here is one (of many) of the snippets I’ve tried.

    function set_post_order_in_admin( $wp_query ) {
    	    $wp_query->set( 'orderby', 'title' );
    	    $wp_query->set( 'order', 'ASC' );       
    add_filter('pre_get_posts', 'set_post_order_in_admin', 5 );
    • This topic was modified 10 months ago by  swani.
Viewing 1 replies (of 1 total)
  • swani


    This is why sleep is important kids. When I deactivated all of the plugins to make sure I didn’t have a conflict, I did it on the staging site (on a server) and checked the results on my local. I wasn’t even looking at the same website! I had a plugin that allows the admin to drag drop posts into order and it was overriding anything I did (as it should). That’s a fun way to spend 90 minutes. Blerg.

Viewing 1 replies (of 1 total)
  • The topic ‘Admin Default Sorting for Custom Post Type’ is closed to new replies.