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)?
- Alphabetical sorting of custom post type – one letter per page
- sort events based on event date custom field
- 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
- Display Woocommerce Orders for specific author [closed]
- Some posts from custom post type to subdomains
- wordpress remove views from action links in a custom post
- $wpdb->get_col and ORDER BY?
- Stores category posts in an array
- Add to ‘action’ within post.php to allow more actions when editing a Custom Post Type in a plugin
- WP_Query not resetting after wp_reset_postdata
- Get post format
- Template code to split a post and print a custom field?
- Make a custom column sortable by a value from a different custom post type
- Send post changes to set email addresses (not users or subscribers)
- Display post from custom post type
- Custom post type title of each author in his own post
- Custom Post type registering as page post type
- Custom Posts and Posts – next_post_link and previous_post_link not working together
- Enable comments for post when comments meta box removed
- How to: Add a publish immediately button when editing custom WordPress posts?
- Extending post by email
- Checking for custom field in admin pages
- Sorting the Loop by Taxonomy Value
- Custom Posttype URL
- Display custom post front end filter by ACF equals current user
- Best way to fix bad count on All | Mine | Published
- open custom post type in popup window instead of page
- Sort products by Sale price and stock status
- Permalink for specific post type
- Orderby if between two meta fields
- Adding specific custom fields (images) to post excerpt
- How to use multiple orderby conditions on query search results? (orderby one post type, relevance)
- How to add custom PHP code in post header?
- How to manage a dynamic multi-level page hierearchy system?
- Custom Post By Category
- How to get the posts that my following users are liked?
- How to insert post 6 times after user register like ask.fm
- Creating custom post type relationships
- How to mark posts as visited
- WP Query with multiple post types ordered by custom meta date then published date
- How To Loop Through list with Custom Post Types
- Adding Information To All Posts Screen
- erase post excerpt limitation [×]
- How do I sort post listing by child post count?
- Pulling in a particular post into a single page based on the post id passed into the code
- Custom My account page and custom page for editing posts
- Get post from custom post type that title is like custom string [closed]
- show posts under custom post type with same autj
- Query order by meta value force specific tag first
- How to make a non-public post on wordpress approval?
- 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