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?
- Admin custom post ordering
- How can i add thumbnails images to particular post (using code not admin pannel) in wordpress
- Showing posts from different categories and from custom post type
- Get latest 3 posts from multiple CPT in one query
- Allow non-logged in users to see a future post after clicking on a list of future posts
- Which post does a taxonomy term belongs to?
- List custom taxonomy specific to one custom post type
- Post image in WordPress not appearing on home page
- How to add a custom-post-type post within another custom-post-type post edit screen using AJAX?
- Meta query for custom post type ignored in main query
- Changing custom type name hides the posts
- How do I create an archive page as a including metadata?
- Display Ad on Specific Categories
- Hiding posts by other users and non-logged in
- Sort CPT archive by order prevents sorting in admin
- Update Post Meta for a logged in user
- Add custom field to Posts and sort by it
- How do I set default meta value by post type?
- Add custom post type settings to wordress default posts
- WP_Query order by custom field, then randomly order some of results
- Get related posts of child term of custom post type
- Two Custom Post Types Many to Many Relationship
- Problem with displaying posts in the CPT category
- JS innerhtml changing style when using AJAX
- How to do WP_Query with two meta fields with orderby clause
- Show titles, date of all posts on single category page
- Store CPT ‘Reviews’ average ratings to a WordPress DB table or to a DB custom table?
- Custom post type, organized by categories
- Side effects of Script and Iframe in post
- WooCommerce sort products by the actual product width(not the shipping width)
- How to change the post type a theme shows by default?
- Set a checkmark in a category based on a URL-parameter
- Several post types on WP Query by tag and taxonomy
- No Permission to add new Page, Post or CPT with Admin role
- Update postmeta Parent when post_status child change
- custom post type category count shortcode
- Portfolio Page for Classic Posts
- How to order and group custom post type posts by year and month
- Order Custom Post Type by Custom Field Value
- Sort and filter custom post type posts by custom taxonomy
- Add post location with mile radius allowing search
- Get the category from custom post type
- Is it possible to store Custom Post Type data in separate set of tables and still have wp_post class functionality?
- Set up post page like JAMA articles
- How to sort posts inside categories
- Custom Post Slug same as Parents Category Slug
- Shortcode not working with post counter
- WordPress posts page for customer filtering and sorting along with category filter
- Changing default ‘posts’ parameters with register_post_type_args
- Admin Column does not populate with data
- manage_edit-{post_type}_sortable_columns sorts, but wrong!
- How to integrate a form (Ninja Form or Contact Form 7) with Custom Post Types?
- Sort entries by date mixing two post types
- Prioritize posts in query by meta keys?
- Homepage’s content is dependent on the custom field values (set automatically), how do I get homepage to update without manually updating page?
- Get the taxonomy of a post hierarchically
- Change sort order when using ‘orderby’ => ‘type’
- Display Woocommerce Orders for specific author [closed]
- Order a custom post type admin screen by a second custom post type title
- Allow users to create posts without logging in?
- How to get all tags of a custom post type by id
- How to define which register_post_status goes to which register_post_type?
- Load Next Posts With AJAX not working with custom post type
- Limit the post for differents custom post type in the same wp_query
- Ordering custom post type by multiple custom fields
- 2 Different Custom Post Types in Submenu
- How to assign classes to all elements?
- How can I show 1 featured post in a styled element, and the next few below differently styled
- Custom order for Mysql array
- Manage Columns : order by post_parent’s title
- Some posts from custom post type to subdomains
- Order by custom field meta_key date and then by custom file meta_key number
- How can i create an custom post template for an specific post category? [closed]
- WP the_posts() on single-cars.php get category link
- Conditional for a Single Post That Belongs to a Category?
- $post not working working in AJAX plugin with custom post type
- Permalink misbehaving in Custom Post Types
- how to get post order by post id wp_query?
- Check post on publish for blank title
- how to check if custom post title exists or not?
- Different Limit number of post on different archive page
- How to change “post_class()” for a custom post type?
- Modify previous and next post links to current Authors Other posts
- Reworking function for counting custom post type posts count
- Create new custom post and post category of same name