pre_get_posts the right hook you need to use.
function CPT_set_default_orderby($q){
global $pagenow, $typenow;
if( is_admin() && 'edit.php' == $pagenow && 'post' == $typenow && !isset($_GET['orderby']) ){
// to order by title
$q->set('orderby', 'title');
// to orderby with meta key
$q->set('orderby', 'meta_key');
$q->set('meta_key', 'expiration');
}
}
add_action('pre_get_posts', 'CPT_set_default_orderby');
Related Posts:
- Using WPAlchemy metabox values in another metabox
- Load a script just to custom post type in admin
- Placing a Custom Post Type Menu Above the Posts Menu Using menu_position?
- Loading External Scripts in Admin but ONLY for a Specific Post Type?
- Merge two custom post types into one admin page?
- Remove the “View” Link in Post Admin
- Add “Last Edited by” column to custom post type list table
- Filter custom post types in admin not working
- Custom post type admin search
- Ordering posts by custom taxonomy in admin area
- Create a dropdown with Custom Post Types as option in admin
- How to add custom columns to Custom Post Type admin screen
- How to Make an admin_notices Message That Disappears Once the User Leaves That Particular Page?
- Prevent reload confirmation after AJAX save
- jQuery UI in Admin (Best Practice?)
- Admin Post Update Redirection to Posts Screen
- Edit the “Post updated. View post” link
- Exclude add_filter from the admin
- No Edit / Delete Links for Custom Post Type?
- Custom Post type sort order not working in the admin area
- Custom admin columns for ALL custom post types
- Add custom column to custom post type overview in backend
- Unable to filter on field on edit.php page
- How to Change the Title of a Meta Box on a Specified Custom Post Type? [duplicate]
- Custom edit post column – category not showing
- No results searching custom post type in admin panel
- How to add post_author column to custom post type
- Adding help information to custom post edit page
- Only Show an Author Their Custom Post Types
- Create and edit posts from front end
- Custom Post Type and taxonomies’s labels localization not working
- How can I add a column in the wp_list_table of the admin area?
- Show admin help message across custom post type parent and child posts
- How to show custom (checkbox) field value in admin post list?
- How to search CPT’s by meta query from the admin dashboard?
- Custom post admin filtering by post meta (the date)
- Admin Column Text Positioning
- Add text to wordpress admin ‘Add Post’ edit
- Sort admin area by custom Event Date field
- How can I change the title of an Add New page in Admin for custom post type
- How to customize admin posts based on the user who is logged in
- Set a default category – if the user didn’t select one- before creating a post
- How can I create a custom meta box to add an mp4 video to a page?
- How to only show posts assigned to current user, only in certain post types
- Add acf field in title (admin table)
- Adding HTML tags or css classes to admin columns
- Prevent stripping MathML tags on post save
- Custom Post Type Capabilities
- Create a page that will be used to create a custom post type
- Get parse_query filter to return slug instead of id
- Custom Post Type Nav to Subpage
- Selecting a post in Dashboard
- Custom admin post.php page
- Is there a way to enable bulk edit and quick edit on custom post types?
- A simple script to allow sorting of custom posts in admin?
- Notify admin on new submit
- Options page – dropdown of users
- No Permission to add new Page, Post or CPT with Admin role
- Filtering posts list table
- CPT Validation to not show “Post updated.”
- Custom post type isn’t working
- Custom posts type for individual pages?
- Use remove_meta_box conditionally on custom post type
- How to group navigation items in the admin panel
- Sortable column containing numeric values for Custom Post Type at WordPress Backend
- How to check if post/page or taxonomy post is published by admin
- CPT Columns doesn’t show categories
- Insert Custom Post Types
- Custom Post Type – Support “author” only for admins
- Showing User’s Post Counts by Custom Post Type in the Author.php?
- Custom page for editing custom post type on frontend based on url
- Add ‘page template’ column to dashboard for CPTs
- Custom Columns for Custom Post Type Manager
- Add data to post edit page, when post is published
- get_post_types not working properly in admin
- Updating post content and custom fields in edit post screen
- Is there a hook between clicking on “Add new” and the edit screen of a new post?
- Function to add custom HTML into head in custom post-type list page
- Multiple custom post types on same admin page
- WordPress admin for a custom post, hide/collapse the main “title” and “description” boxes
- Metaboxes inside Tab
- How can I put content before my custom post type default pages?
- How we can create menu from Appearance > Menu and use as a add-submenu-page for admin menu?
- Is there any filter to add a custom attribute to the tag in admin panel?
- How to hide private posts even if user is admin
- Adding orderby url parameter to main CPT admin menu link
- Help Adding filter to Add Media button for custom post type
- Delete all custom posts then upload a new CSV of events
- Pagination in wp-admin for CPT
- Edit is changing my custom’s post type parent id
- Custom post type doesn’t display on admin list
- Shared Custom post type between WP network sites
- Admin menu post type
- WordPress Author Posts Review After Every Change In The Same WordPress Post
- Redirect preview single post link to a page
- Change column of row action (Quick Edit) links in WP_List_Table
- Prevent users from changing post status
- Custom Plugin w/ Custom Post Types – Custom Posts Are Showing at all Privilege Levels – Is this possible to adjust?
- How to set the Screen Options for Users in the Admin Panel?
- Admin menu link with variable