Hi -
I'm looking to pass Post IDs into a View (using the shortcode parameter, as it will vary from page to page) and I want to maintain the order of the posts as passed. I.e. [wpv-name posts="10,5,200"]... should display posts in the order 10, 5, 200 - not in the SQL-native order of 5, 10, 200.
Here is a thread from a few years ago:
https://toolset.com/forums/topic/order-the-items-in-a-view-by-ids-order-not-ascending-or-descending/
I can see & use the fix - but I was wondering why you guys can't just add an "Order by Post__In" option to the UI for the Views page? This has been supported in WP core since (I think) v3.5.
Thanks
I think perhaps the filter priority needs to be > 99. It doesn't work for me when priority is 99, but does work when set to 999.
Ok thanks @Beda - I guess the ticket from 3 years back just used the wrong priority.
Any ETA on when you guys might add "Order by post__in" to the native View options? Seems like it would be an easy addition to the dropdown & $query_args logic, no? In fact, it actually seems to already work when you set it in the Views shortcode manually like:
`{!{wpv-view name='...' postids='355,370,372...' orderby='post__in'}!}`
Thanks!
Well, we use that in several places yes.
https://toolset.com/forums/topic/add-post__in-as-order-by-option/#post-515214
But ordering by it won't be implemented.
Thanks Beda. That's funny that you referenced my request from a year ago 🙂
I still don't quite understand the limitation you mention, but since that filter is easy enough to add, it's not a big deal.
In case this helps anyone else looking for a programmatic way to order by post__in, I've found that you can't pass 'post__in' directly into the shortcode because Views strips the string "post" out of any value.
However you can pass a custom value (like orderby='ids') then have the filter function catch any shortcode with that param value, and update it to be 'post__in'. That way, you don't need to hard-code View IDs into your filter.