• Resolved SpankMarvin

    (@spankmarvin)


    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

Viewing 9 replies - 1 through 9 (of 9 total)
  • 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]

    Thread Starter SpankMarvin

    (@spankmarvin)

    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

    Thread Starter SpankMarvin

    (@spankmarvin)

    Oh, it seems to have removed the code…

    alturnwall

    (@alturnwall)

    @vtxyzzy, could you possibly paste that code again since it’s been removed? Thanks!

    vtxyzzy

    (@vtxyzzy)

    I’ll have to recreate it, but will post a link when done.

    Thread Starter SpankMarvin

    (@spankmarvin)

    I have a copy of the code. To save you the bother:

    Sorry, edit: Here is the pastebin link

    vtxyzzy

    (@vtxyzzy)

    Here you go – new and improved:

    http://pastebin.com/3vwiDSfb

    alturnwall

    (@alturnwall)

    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!

    vtxyzzy

    (@vtxyzzy)

    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.

Viewing 9 replies - 1 through 9 (of 9 total)

The topic ‘Order by page__in array sequence?’ is closed to new replies.