I have a custom Wordpress query that is using an array of product IDs that exist in an ACF field(these IDs do not line up with the Wordpress post IDs). I would like for the order of the returned posts to match the order of the array that is specified in the meta_query
value
. Here is what my meta query looks like:
$product_ids = array('3624', '1298', '430', '5629', '765');
$meta_query = array(
'relation' => 'AND',
array(
'key' => 'product_id',
'value' => $product_ids,
'compare' => 'IN'
),
);
So, for instance, in the returned results I want the first product to be product ID 3624
, and the last product to be 765
. Is there a way to order the query results so that the order of the returned posts matches the order of the array specified in the meta query? I tried leaving orderby
blank, but that seems to default to sorting by post ID. I also tried setting orderby
to none
, but that didn't seem to work either.