Possible to order archive by selected post IDs, followed by regular order with WP_Query

I can run an SQL query like ORDER BY FIELD( id, 3, 2, 1, 4 ), title and return a list of posts starting with my ids 3,2,1,4 and the continuing with the rest of a query, bringing back all remaining posts.

I’m trying to figure out if it’s possible to make something similar to sticky posts.

Scenario:

I’ve got an ACF field attached to an archive page. This field allows you to choose IDs of posts in this archive.

I want to modify the archive loop to priorities the ACF IDs (Treat this as an array)

Ideally, I don’t want to run a query twice to get the same details, but it’s my only option at the moments.

Running a post__in loop followed by a post__not_in, but having to deal with pagination. It’s a bit of a headache.

Is there a way to directly modify a WP_Query object that forces an array of IDs to be the first results that respects pagination etc.

Read more here:: Possible to order archive by selected post IDs, followed by regular order with WP_Query

Leave a Reply

Your email address will not be published. Required fields are marked *