Here’s code that will order posts by the post_title field, numerically. This code will affect the main query for posts on both the back end and front end.
// Apply numeric post ordering for posts in admin and front end.
// Adapted from https://www.fldtrace.com/custom-post-types-numeric-title-order
function wpse247871_post_order( $wp_query ) {
if ( $wp_query->is_main_query() && $wp_query->query['post_type'] == 'post' ) {
add_filter( 'posts_orderby', 'wpse247871_orderby_post_title_int' );
}
}
add_filter('pre_get_posts', 'wpse247871_post_order');
// Cast the post_title field as an integer in SQL.
function wpse247871_orderby_post_title_int( $orderby ) {
global $wpdb;
return "({$wpdb->prefix}posts.post_title+0) ASC";
}
Related Posts:
- How to Change Order of Posts in Admin?
- Get current menu_order
- Different post sort order within different categories
- what types of order can I pass to get_posts() via orderby?
- Sort posts by popularity/page views
- How do I reorder (pop and push) items from WP_Query?
- How to put last edited entry on top of the blog-post list?
- Sort post by attributes ‘order’
- How to sort posts by last name (2nd word) on ONE category only?
- Query posts from current year
- Reverse chronology of post listing
- Order Posts by Alphabetical for Each Letter
- Set number of article per number of page
- How to choose a sort order (for posts) per category? (ideally when creating a new category)
- Order post by year DESC and month ASC
- Display custom post types by date field
- orderby=meta_value_num creates duplicate posts
- Change Order of Admin Posts Depending on Meta
- Display posts in alphabetical order for a particular category
- post re-order on my site
- Display posts from #6 to #20 on archive page
- Why orderby=”date” does not support manually changed posts?
- WP_Query orderby not working with meta_value_num and menu_order
- How can I sort posts by the date and a custom meta field?
- Sort WP posts by span value
- How to sort posts inside categories
- Any way for get_next_post() to use the actual post order instead of publish order?
- Custom order for Mysql array
- How to order posts by meta_value and title
- Order posts alphabetically: how to set order=asc in mysql query?
- how to get post order by post id wp_query?
- How Do I Get My Post Tags to Alphabetize?
- While loop articles – if statement order
- Make a vertical dynamic list of posts in alphabetically order and in columns [closed]
- Create a list of posts with topic headdings
- How can I add a box to edit Order on a regular post?
- get_previous_post() while accounting for sticky posts
- Need to know custom code to display random and most viewed posts in wordpress posts and pages
- Posts and order
- Adjust the order for returned posts
- Order posts by date
- query posts with selected post ids first
- How do I display posts ordered by a date custom field?
- WP_Query sort by meta_value_num or date
- Allow reader to reorder posts for themselves (oldest first)
- Random order of the 5 most popular posts
- My custom query is displaying random posts in random order
- Get query result according to merged array
- How to make post button to a random post
- Where is object, property or label in the database that controls the order of the posts being displayed?
- Last three posts not being put in order by date. How to fix this?
- Order by ‘s’ using WP_Query()
- Custom Admin Post Column change order
- How to sort posts alphabetically based on a specific parent category
- How to export posts with featured image
- How are terms connected with posts in database?
- JSON not valid after json_encode posts
- Creating new page with pre-defined parent page
- How To Add Perfect Apostrophe And Quotation Mark In WordPress Posts?
- Send email to user that his post has been rejected
- Custom post type permalinks breaking due to 3.1 bug fix
- wp_insert_post let users post to without login…broke
- Export posts manually selected by end user (not logged in)
- Loop through all product posts?
- How to add Tags Filter in wordpress admin dashboard
- How to display featured image without it appearing in post?
- allow new users to post an article before they sign up [closed]
- Ajax post filters not working
- Making a custom Pagination for multi page blog post
- plugin to post from admin to flickr [closed]
- store posts_id of category into a varable?
- Get post meta retrieving wrong value
- How safe is it to delete old posts edits to save database space?
- If contributor has published 2 or more posts then show otherwise hide
- How to Assign / Move all Deleted post to a category
- Using wp-cli and delete everypost first image
- Assigning Two Different Post Dates For Single Post
- Show posts by quarter
- Inserting an example of the last 3 post on to the homepage
- Sidebar limiting to 10 posts?
- How to associate a custom taxonomy to a post multiple times
- Post date automatically +100 years into the future
- Can I show category name in url for only one of my categories?
- How to let a user create a post by submitting a POST form?
- Disable pagination in posts and pages
- wpautop filter off for pages but on for posts
- post categories – how to show only categories with a specific parent id
- How do I create a ‘selection’ criteria list’ that will then dictate which posts are generated when the user presses search?
- Post URL duplication adds numerical value
- get “read more” with custom DB query like you would with WP Query
- Body text disappearing in random posts
- Add default content to post (for specific category)
- Displaying posts on Homepage
- Adding a time stamp on post view
- The post order is different for logged-in and non-logged-in users? [closed]
- Change a div background color on Post ID
- How can add custom commands in post-new.php in wordpress
- Filter/Sort Post Form On Taxonomy page
- Display post by select it from a dropdown menu
- Error counting posts of category