Home › Forums › Backend Issues (wp-admin) › How to dynamically populate repeated with all posts from a custom type? › Reply To: How to dynamically populate repeated with all posts from a custom type?
add_filter('acf/load_value/name=post_object_repeater', 'prepopulate_post_object_with_all_posts', 20, 3);
function prepopulate_post_object_with_all_posts($value, $post_id, $field) {
if (!empty($value)) {
// already has a value, do not overwrite
return $value;
}
// do a query to get all posts of the post type
$args = array(
'post_type' => 'add-ons', // your post type
'posts_per_page' => -1, // -1 get all
'fields' => 'ids', // return only list of IDs
);
$query = new WP_Query($args);
if (empty($query->posts)) {
// no posts found
return $value;
}
$value = $query->posts;
return $value;
}
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.