I think the simplest, but not necessarily the most performant, would be using two WP_Query loops, one using $query->set( 'post__in', $product_ids_on_sale );
and other using $query->set( 'post__not__in', $product_ids_on_sale );
because these are mutually exclusive. One loop would be used for the main query and other for second loop as show in this example in the documentation.
You would need to account for the number of items in each loop based on the number of items in the $product_ids_on_sale
variable AND pagination. And I would the main query for the products NOT in sale.
Related Posts:
- Custom Table Column Sortable by Taxonomy Query
- How to Change Order of Posts in Admin?
- visually sort ordering “custom post types” for end users
- sort child pages on admin
- Adding meta_key via pre_get_posts causes navigation to disappear
- How do I allow users to sort posts? [duplicate]
- Sorting results from JSON-API on custom fields
- Sort users in get_users() in custom order
- Sorting Posts by custom field
- Sort by custom field value
- How to sort posts with the first 2 or 3 by latest, and the rest is random?
- Get “wp_get_nav_menu_items” to sort alphabetically [duplicate]
- Ascending sort order for monthly & category view, i.e. ?m=201204, ?cat=4
- Adding Sorting to Website?
- Sorting by tag or category
- get_terms orderby name as numbers
- How to sort posts in admin by titles with dd.mm.yyyy format?
- Creating a category page by alphabet
- Using database meta_values to calculate new post order using pre_get_posts or a ‘request’ hook
- Sorting get_post_ancestors array
- wordpress custom_meta ordering of timestamps
- Multi-level ordering in WordPress
- Sorting for custom column in WordPress admin post table
- Sorting and limitation with pre_get_posts
- Help alphabetically sorting $terms from get terms(‘wpsc_product_category’
- Vertical alphabetically post columns
- Advanced custom fields sort repeater by date
- Use pre_get_posts to sort meta_key by an array of values
- Displaying posts sorting by a custom criterion
- Sorting custom post type by usermeta
- Sort posts by meta key that is serialised with other meta keys
- orderby field – list of available options?
- User Query sort on custom field then name
- Sort the result of the main Query in shop page by a custom taxonomy
- WP Query sort by meta value
- Help ordering Post loop by two meta values
- Best Practices for a Completely Customizable Homepage – without plugins
- Sorting posts by custom field value
- How do I create a sort capability by Title, Category, Author, Date?
- How to avoid duplicating same meta_value?
- Sorting/Filter posts from front-end in WordPress blog
- ‘sort_column’ => ‘menu_order’ not working
- Sort scheduled posts in ascending order by default
- How to sort by number
- sort items by randomness
- Sorting search results with custom dropdown
- inner foreach loop sorting
- Sortby parameter to sort users
- Update meta_key value for a page
- Sort my event calendar by date
- Table Sorter sort by span title?
- Sort categories by custom field in WordPress admin
- make two custom columns sortables
- Order column custom date using pre_get_posts
- ACF pro: Group teaser by datepicker year and display custom sub fields [closed]
- Sorting in WP_List_Table class
- Sort an array with an ACF meta key
- New custom post type entries are not sorted correctly in admin using pre_get_posts
- display wordpress user who published a pending post of another user
- Static front page and orderby
- Advanced sorting of content in wordpress [closed]
- Sort posts by first content letter
- Grouping posts starting with same letter
- How do I sort post listing by child post count?
- Getshopped (WP-e-commerce): show all protucts on one admin page for drag-and-drop ordering [closed]
- List CPT by menu_order with children right after parent
- Multidimensional array sort?
- How can users sort multiple pages?
- Posts sortable column not sorting properly for custom field numbers
- How do i Sort my Posts
- How to resort my id in wordpress?
- Custom taxonomy with custom meta value is not sorting correctly (query returns the same value for orderby regardless of sort column click)
- Sorting by Title for Post Archive Categories for Custom Post Type
- Sort Featured Content by Order instead of ID
- Sort posts by numeric value of custom field, and also show any other posts without that custom field
- Sort posts by numeric value of custom field, and also show any other posts without that custom field
- When to use WP_query(), query_posts() and pre_get_posts
- Sort on meta value but include posts that don’t have one
- Can the Next/Prev Post links be ordered by menu order or by a meta key?
- Can I exclude a post by meta key using pre_get_posts function?
- Should I use Pre Get Posts or WP_Query
- Query to sort a list by meta key first (if it exists), and show remaining posts without meta key ordered by title
- Using pre_get_posts with WP_Query
- Sticky Posts exceed posts per page limit
- Sort results by name & asc order on Archive.php
- Using pre_get_posts on true pages and static front pages
- Theres a way to use $query->set(‘tax_query’ in pre_get_posts filter?
- Modify Taxonomy pages to exclude items in child taxonomies
- How do I set the default admin sort order for a custom post type to a custom column?
- Ignoring initial articles (like ‘a’, ‘an’ or ‘the’) when sorting queries?
- Make custom column sortable
- WP_Query orderby post__in remains ineffective in the Loop [closed]
- Sort pages in loop by admin’s page attributes order field?
- Orderby meta_value only returns posts that have existing meta_key
- Using meta_query, how can i filter by a custom field and order by another one?
- Sort admin menu items
- Media library to list images only user uploaded
- multiple orderby in pre_get_posts action
- ORDER BY custom field value
- What is “main query”? [duplicate]