If your naming system is consistent then simply ordering by the post name should do it:
$args = array(
'orderby' => 'title',
'order' => 'ASC',
);
$q = new WP_Query($args);
var_dump($q->request);
var_dump(wp_list_pluck($q->posts,'post_title'));
Or, as a pre_get_posts
filter (assuming the main query is what we want to alter):
add_action(
'pre_get_posts',
function ($qry) {
if ($qry->is_main_query()) {
$qry->set('orderby','title');
}
}
);
This is what I’d consider a fragile solution. A more complicated one, but more reliable, would be to save custom meta for your IDs and order by that custom meta.
If you have the data saved as custom meta then use these arguments instead:
$args = array(
'meta_key' => 'SKU', // maybe sku; or whatever your KEY is
'orderby' => 'meta_value',
'order' => 'ASC',
);
Related Posts:
- Customize the Sorting Dropdown in WooCommerce use another list or more page
- Custom Woocommerce Product Query
- How sort products by calculate value? ( custom post meta, price, option)
- Ignoring initial articles (like ‘a’, ‘an’ or ‘the’) when sorting queries?
- Sorting: custom query with orderby meta_value_num THEN by title
- How to query only for products with status “in stock” in WooCommerce? [closed]
- Sort posts by category name and title
- Query WooCommerce orders where meta data does not exist
- How to get Page/Post Gallery attachment images in order they are set in backend using WP_Query()?
- WP_Query for WooCommerce Products
- Get WooCommerce best selling products for the current month [closed]
- Loop through all tags & output posts in alphabetical list
- Woocommerce query by price range and custom meta key
- Sorting Posts by custom field
- How to combine tax_query and date_query in WordPress
- Sorting meta_value as integer doesn’t work
- how to retrieve specific product attribute value in an sql query?
- Sort in WP_Query(), not filter? Is it possible?
- Find all product that contain terms with %keywords% in WP_Query
- Front End Sorting Questions
- Sort by meta key on archive page
- WP Query – Get WooCommerce Products with variation that is in stock
- How to sort posts in admin by titles with dd.mm.yyyy format?
- Search product by brand name in wp_query
- How to make orderby ‘meta_value_num’ OPTIONAL?
- Meta query with order by another custom field
- How do I sort posts with multiple pages
- WP_Query posts by distance based on LAT & LNG in Database
- Woocommerce returns Product post_status as published even tho it is in status draft
- Changing WP_Query params with url Query Var
- showing all search result in one template
- Get all products which have both product category
- Woocommerce query all products and categories
- Sort wordpress custom posts based on meta value
- WP_QUERY to display woocommerce products whose author IS the logged in user
- WP_Query: Group events by year, sorted DESC; then by date for each year group, sorted ASC
- WordPress Comments sort by custom meta key
- Understanding the orderby in WP_Query?
- WooCommerce – get product sub categories
- WP_query sorting can’t sort danish letters (æ, ø, å)
- Having trouble with WooCommerce Storefront child theme single.php “related posts” modification [closed]
- Out Of memory issue on post per page parameter
- Help ordering Post loop by two meta values
- How to sort a custom wordpress query by combination of meta values?
- Gallery shortcode numerical sorting
- wp_query not working with post_type
- Need Sub-category with main Category
- Woocommerce pagination and result count after custom loop
- I am having problem sorting custom post type using WP_Query
- Can’t fetch Custom Post Type Data through Custom Query
- How do I get Woocommerce product variation name and variation description in a WP_Query?
- Exclude a Woocommerce product from WP_Query
- Multiple meta_key ordering with pre_get_posts
- Sorting search results with custom dropdown
- Display all posts in a custom post type, grouped by a custom taxonomy. How to sort the posts alphabetically and the terms by ID?
- var_dump of WP_Query object is not empty, while .have_posts() return false
- How do I sort this custom list of sticky posts
- WP Query and date format
- How to sort queried pages by an array of page ids?
- Tax Query on product_cat using NOT IN as operator does not exclude that category
- Woocommerce Shortcode which displays a table with product data
- Order (by ASC) posts with meta_key so posts without values are last
- How to sort store location by specific category order in WP store locations
- how to include orderby value that is empty?
- How to sort wordpress posts already selected by WP_QUERY
- Sort by price wpdb
- WooCommerce WP_Query using tax_query returns no results (0 = 1)
- wc_get_products() return empty object
- How can I filter products by meta in Woocommerce REST API?
- WooCommerce. How To Exclude Subcategory Products From Category Listing Page
- get_posts return only first result
- Get authors list and sort them by recent posts
- Select multiple categories with is_tax
- Order by value of Custom Field using url string
- WP Query with meta queries
- update_post_meta performance in a loop woocommerce
- update_post_meta performance in a loop woocommerce
- Case insensitive ORDERBY in wpquery
- Query child posts with tax query on parents
- Sort posts on custom field AND after that sort on date?
- How to mix two orderby-parameters into one ordered result
- Slow Query with more 100 products
- Sorting Posts by Taxonomy thats not within the query’s $args
- Create global array to compare inside a query
- How do i query woocommerce booking post type on init action?
- How to add in WP_Query to every 3 posts displayed? [duplicate]
- Ignoring ‘a’ when sorting posts
- Display three sequential posts on each page load, without repeating previous
- Combine WP_Query with array of custom data to single loop without breaking the pagination
- Woocommerce orderby rand with tax_query not random
- Sorting is not working in WordPress WP_Query
- How to sort a WP_Query array by post_name after an array_merge();
- query_posts with sorting on a custom datestamp
- Sort Posts with custom meta key by default which is currently set as optional
- wordpress sorting using array merge by price in ascending order but price with 0 must be show last
- Show linked products using wp query and woocommerce
- have_posts order by title descending
- WP_Query – order with usort by custom meta
- WP_Query (or WC_Product_Query) out of memory
- Sort by multiple columns using get_posts