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
- WP_Query: Exclude hidden products from WooCommerce product list
- How to query only for products with status “in stock” in WooCommerce? [closed]
- Sort posts by category name and title
- How to get order of posts?
- 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 orderby meta key natural sort?
- WP_Query for WooCommerce Products
- Changing a theme’s search function to only show results from woocommerce?
- 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
- WooCommerce: filter by parent product’s taxonomy and product variation’s meta data
- Retrieve products with specific attribute and in category – woocommerce
- 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
- WP_Query for products always returns empty
- Unlimited Page Sitemap Link
- How to sort queried pages by an array of page ids?
- orderby ignored by wp_query
- $wp_query->found_posts not returning correct value
- Tax Query on product_cat using NOT IN as operator does not exclude that category
- Woocommerce Shortcode which displays a table with product data
- Make a products only viewable to a specific user ID in meta_query pre_get_posts
- 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
- ElasticPress is (aparently) messing with my search filters
- how to include orderby value that is empty?
- How to sort wordpress posts already selected by WP_QUERY
- Woocommerce Get Orders By Meta Value
- Save large WP_Query to transient === false
- 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
- What code to use in an array to call the current sub-category?
- Move some posts to end of sort order, even if there is a sort in the wp_Query already
- Get categories within specific term
- Select multiple categories with is_tax
- Order by value of Custom Field using url string
- How to display Woocommerce products list by tag
- WP Query with meta queries
- Woocommerce featured products query no longer working
- Ajax buttons not working properly in WooCommerce when using wc_get_template_part
- update_post_meta performance in a loop woocommerce
- update_post_meta performance in a loop woocommerce
- Order 2 meta_queries differently in WP_Query?
- 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
- Woocomerce – Order products by float attribute in archive pages
- Not able to fetch woocommerce variation sales products for particular category products
- 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
- Get posts with any value in attribute
- How do i query woocommerce booking post type on init action?
- WP_Query to Retrieve Posts from WooCommerce Products that are Only in Catalog
- How to add in WP_Query to every 3 posts displayed? [duplicate]
- Ignoring ‘a’ when sorting posts
- Woocommerce WP_Query post__not_in problem
- Display three sequential posts on each page load, without repeating previous
- Using the same WP_Query for shop and widgets in WooCommerce shop
- Combine WP_Query with array of custom data to single loop without breaking the pagination
- Woocommerce orderby rand with tax_query not random
- Wrap group of wp query posts to parent div by date/year
- Sorting posts by meta values: 2 different orders
- Sorting is not working in WordPress WP_Query
- How to sort a WP_Query array by post_name after an array_merge();
- Sorting: custom query with orderby meta_value_num THEN by title
- 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
- Adding arguments to WooCommerce Product Loop using AJAX
- Show linked products using wp query and woocommerce
- have_posts order by title descending
- WP_Query – order with usort by custom meta
- Filtering product search results using tags
- Woocommerce set loop_shop_columns to be 3 in the main shop page loop only and 4 otherwise
- Variations as Single Products [closed]
- WP_Query (or WC_Product_Query) out of memory
- Sort by multiple columns using get_posts
- How to get products with the same custom attribute like ean code
- WP Query order posts not working
- How to `’orderby’ => ‘meta_value_num’` in a series of orderby parameters
- query loop “inherit query from template” prevents setting sort order
- How could i add username field in WooCommerce