Merging get_posts returned arrays
-
I’ve searched everywhere and can’t quite wrap my head around a particular issue I’m working on.
What I’m trying to do is get all the images belonging to a particular custom post type and category. I’ve got it worked out already where it returns the separate arrays for each post in that custom post type. However, I actually have the need to randomize the order of the images that are returned.
Currently, the posts are returned randomly (e.g. Post 1, Post 2 and Post 3 will return and display in a random order) and the images per post are randomized as well (e.g. Post 1 images will return in a random order), but they are still grouped by post (Post 1 images do not get intermixed with Post 2 images and so forth).
What I need is it to be a random order where it displays images like:
Post 1 – Image 2
Post 2 – Image 3
Post 1 – Image 1
Post 3 – Image 4
Post 2 – Image 5In the pastebin is what I currently am using. I also have another version using a custom WP_Query, but I get the same results, as the
foreach()
will output an array for the first post, then an array for the second post, etc.Is there a way to merge the arrays returned from
get_posts()
and then work through that with aforeach()
? Or am I missing something completely simple.
- The topic ‘Merging get_posts returned arrays’ is closed to new replies.