The orderby argument is limited by what is possible in MySQL, and it’s not good at natural alphanumeric sorting like you describe. Possible options include:
- Rewriting the values with leading zeros, e.g. “CA05”
- Creating a separate “Sort Order” column that just stores an integer, and ordering by that.
-
Separating the letters and numbers into two separate fields. Then writing a more complex query to sort by two different meta values:
$query->set( 'meta_query', array( 'relation' => 'AND', 'letter_clause' => array( 'key' => 'letter', ), 'number_clause' => array( 'key' => 'number', 'type' => 'NUMERIC' ) ); $query->set( 'orderby', array( 'letter_clause' => 'ASC', 'number_clause' => 'ASC' );More info on that syntax here: https://www.billerickson.net/wp-query-sort-by-meta/
Related Posts:
- Sort Order for a Custom Query in a Post Type Archive Not Working
- WP_Query -> sort results by relevance (= most tags / taxonomy terms in common)
- Custom Post type sort order not working in the admin area
- ascending order custom post type
- Combining sorted and random CPT
- Wp_query: sort by PHP variable
- How to sort posts in a custom post type by title in ascending order by default?
- Custom post type sorting: alphabetical order
- Sort column on meta key and meta value
- Display Parent-Child Posts in specific order by comparing IDs in array
- Custom post type order by post_title
- SEARCH QUERIES – REVERSE OUTPUT
- order custom post type posts by custom date
- Wp Query sort order from custom MetaBox
- How to sort custom post’s category by id from the theme’s function.php?
- How do I set the default admin sort order for a custom post type to a custom column?
- Submit post and upload image from front-end
- Linking Two Post Types
- Custom Post Type, WP_Query and ‘orderby’
- Pull Two Posts Into Custom Post Type `single-cpt.php`
- Problem excluding category from get_next_post
- Why is the »_builtin« parameter not advised in »register_post_type()« for custom post types?
- Compare 3 custom fields and sort by oldest
- How to let custom post type posts show in standard post archive (like in homepage)?
- Rewrite custom post & taxonomy to share same URL path
- Alphabetical sorting of custom post type – one letter per page
- sort events based on event date custom field
- Get the post children count of a post
- Quickest way to get last or oldest post date – WP Query
- How to use custom fields to enable sticky posts on custom post types?
- Custom-post-type-archive: posts sorted/filtered by year?
- get_template_part for custom post type content not working
- Show Two custom Post type and their posts on category page
- count_many_users_posts except current logged in user?
- Custom post type and body_class: Remove “blog” class
- Find the user who initially created the post
- How to get the post type from a category id?
- Is there a way to have the view link on manage posts page to open in a new window or tab?
- How i can add ‘N’ page of ‘N’ pages under posts loop?
- Getting posts under the custom post type ui category
- create parent post using wp_insert_post
- Turn on and off custom post type from admin?
- How to order separated Custom Post Search results
- I would like to have different styles for my posts based on the content of each post
- List custom taxonomy specific to one custom post type
- How do I set default meta value by post type?
- Add custom post type settings to wordress default posts
- JS innerhtml changing style when using AJAX
- Custom post type, organized by categories
- Side effects of Script and Iframe in post
- Several post types on WP Query by tag and taxonomy
- How to sort posts inside categories
- Admin Column does not populate with data
- Display Woocommerce Orders for specific author [closed]
- Permalink misbehaving in Custom Post Types
- Is it a good idea to add a column to the posts table?
- Display Only Certain Category In a Custom Page Template
- Creating separate feeds for custom post types
- Auto post creation
- Easy reading or transfer of data from posts?
- list posts of two post types in a single template
- The loop does not show users
- Front-end Image Upload to Custom Meta Box
- Create a custom post type based on ‘Post’
- Invalid content when I try to import custom post type from the old template wordpress
- Why is my custom post content only viewable when signed into WordPress?
- Sort custom posts by date and then by taxonomy
- Add a form in every post and save data in post meta
- How to set post date in post_type so that it’s same as latest post in category
- How to use multiple Meta Field from CPT as Post permalink
- Custom post type sortable columns when column value is from a custom database value
- Right way to store a large set of similar information on website? [duplicate]
- Create a post automatically if search result has zero results
- Correct way adding External classes to Custom Post type and output their methods to template
- Assign a Post to a User
- Cannot save pages after migration
- Bulk trashing post ‘fails’
- Rest Api not working with Iframe in form data
- Delete Post by User
- Only show current category post
- WordPress Contents Migration
- Problem to get the link of the default ‘post’ post type like the orther custom types
- Featured image in custom post is being disabled
- How to set class to “current-page” on the currently viewed single post within a CPT
- Help ordering custom query by Title, Ascending
- Getting wrong ID
- How to make post page unique and show it on home page?
- How to display custom post type ordered by a custom field date
- Ordering custom post type by custom field without a title
- Query Only Show Text on Posts With Certain Taxonomy Tag
- Query Posts From Multiple Post Types
- Posts 2 Posts: query connected — orderby problem
- How to make a template for a specific post of a custom post type?
- How to hide home title on pages and posts?
- Front end post or photo or both
- Can WordPress show posts based on a button that the user clicked 2 pages back?
- How Do I Add a Custom Post Type URL to Content?
- is therer any wordpress function to retrieve a specific html element from post content
- How to sort posts alphabetically based on a specific parent category
- button onclick with get_post_permalink