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
- Order by Post Title in WP Query not working
- Get WordPress post content by post id
- Get page ID of page that is set as the posts page
- Get Posts Under Custom Taxonomy
- How to limit the number of posts that WP_Query gets?
- Stop WordPress Wrapping Images In A “P” Tag
- When is the ‘post_content_filtered’ column in database cleared by WordPress?
- Turn a URL into an Attachment / Post ID
- GET the excerpt by ID
- Stop WordPress automatically adding tags to post content
- Determine if page is the Posts Page
- How to get ‘post_content’ without stripping tags?
- How to add an admin notice upon post save/update
- Print Current Post Index number within Loop
- Should we trust the post globals?
- Optimize post insert and delete for bulk operations?
- Get the Current Page Number
- How do you add thumbnail support for custom post types?
- How to mark every 3rd post
- Change Posts per page count
- Keep featured content post in homepage with original order
- How to display related posts from same category?
- Can posts have parents?
- Is there a action hook for the “Empty Trash” button?
- How to end the excerpt with a sentence rather than a word?
- How do I check if I linked to a post before I delete it?
- How to change the case of all post titles to “Title Case”
- Appending content with broken in 4.4
- How to get posts published between a date and today?
- ZIP up all images displayed in a [gallery] and offer as download link
- How to detect single.php (but not single-portfolio.php)?
- How to check if post meta key exists or not in wordpress database
- How to remove a column from the Posts page
- removing inline styles from wp-caption div
- What is the use of to_ping and pinged column?
- How to use “Add link” pop up for a WordPress widget
- Remove Categories / Tags From Admin Menu
- How to retrieve text only from wp_content() not from wp_excerpt()?
- Stop WP from creating “Sample Page” and “Hello World!” post
- Where is the old post permalink slug stored?
- How to Create Editable Blocks of Text for the Homepage?
- Keyboard shortcut for updating a page or post?
- Add custom Attachment Display Setting for images
- Rewriting post slug before post save
- Apply the_title() filter in post & page title, but not in menu title
- is it possible to get next_post_link