Hi there
I am feeding a list of page IDs into a custom query, and would like to have the pages listed in the same order as they appear in the array. I am aware I could probably do a foreach on the array and within that loop, run get_page, but I'm wondering if it's possible to call a loop using page__in and order as per the array of IDs? This would be the ideal situation. If not I'll just go with the foreach / get_page combo.
Thanks in advance for any advice,
John
Here is a sample script that should get you started. The list of IDs is kept in an array and passed as an argument to the query.
After the query, an index of IDs is created with their index in the $wp_query->posts array. Then, a new $wp_query->posts array is created in the desired order.
[Code moderated as per the Forum Rules. Please use the pastebin]
Fantastic. This is precisely what I was looking for in the absence of a parameter to do the hard work for me.
I'll give this a try later tonight. Thank you for your time on this.
John
Oh, it seems to have removed the code...
alturnwall
Member
Posted 11 months ago #
@vtxyzzy, could you possibly paste that code again since it's been removed? Thanks!
I'll have to recreate it, but will post a link when done.
I have a copy of the code. To save you the bother:
Sorry, edit: Here is the pastebin link
Here you go - new and improved:
http://pastebin.com/3vwiDSfb
alturnwall
Member
Posted 11 months ago #
Ah, you guys are amazing!
I used @vtxyzzy's latest pastebin since it was a tad simpler and it works like a charm.
Thank you!
If your problem has been solved, please use the dropdown on the right to mark this topic 'Resolved' so that anyone else with this question can see that there is a solution.