Site logo

[Resolved] default sort elements = orderby date desc

Home Forums Support [Resolved] default sort elements = orderby date desc

Home Forums Support default sort elements = orderby date desc

  • This topic has 3 replies, 2 voices, and was last updated 3 years ago by David.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #2525853
    Webmaster

    Hi GP Team,

    I find myself in the Elements area often but I’m always clicking the Date column to sort by most recent. Might you know of a php snippet I can use to make it so it always sorts by this when I click the sidebar WP Admin > Appearance > “Elements” sidebar link? Basically, I’d love to append &orderby=date&order=desc to the sidebar link.

    https://i.imgur.com/QIMuRNd.png

    https://i.imgur.com/OponnaG.png

    Happy Wednesday,

    #2526169
    David
    Staff
    Customer Support

    Hi there,

    give this PHP Snippet a shot:

    function set_post_order_in_admin( $wp_query ) {
        global $typenow;
        $post_type = 'gp_elements';
        
        if ( is_admin() && $typenow == $post_type && !isset($_GET['orderby'])) {
            $wp_query->set( 'orderby', 'date' );
            $wp_query->set( 'order', 'DESC' );       
        }
    }
        
    add_filter('pre_get_posts', 'set_post_order_in_admin', 5 );
    #2526400
    Webmaster

    Hell yea brother – solved!

    Best of success to you on this fine Wednesday.

    #2526978
    David
    Staff
    Customer Support

    Glad to hear that !!

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.