Home › Forums › Front-end Issues › Post Object field with multiple posts into a WP_Query or while loop? › Reply To: Post Object field with multiple posts into a WP_Query or while loop?
Hello…
With WP_Query you can use the argument post__in to pass in an array of post IDs…
See here: https://codex.wordpress.org/Class_Reference/WP_Query#Post_.26_Page_Parameters
So… with a Post Object ACF filed, you might be returning IDs or Post Objects (default).
If returning Post Objects, you can use this code to get an array of IDs:
$post_objects = get_field('po');
$post_object_ids = array_map(function($o) { return $o->ID; }, $post_objects); // array of IDs to pass to: post__in in a WP_Query
Careful though about passing an empty array to post__in because it will return all results.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.