Site logo

Archived topic

default sort elements = orderby date desc

3 replies · Started by Webmaster on February 8, 2023

Viewing posts 1–4 of 4

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,

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 );

Hell yea brother - solved!

Best of success to you on this fine Wednesday.

Glad to hear that !!

This archived topic is closed to new replies.