Home › Forums › ACF PRO › Max items for post object field › Reply To: Max items for post object field
You could use a relationship field instead. A post object field that allows multiple values is just another way of displaying a relationship field.
Or you can create an acf/validate_value filter https://www.advancedcustomfields.com/resources/acf-validate_value/. $value in this case will be an array of post IDs and you can do
if (count($value) > $my_max_posts) {
$valid = 'No more than '.$my_max_posts.' allowed';
}
I’d also add a note to the field instructions about the maximum.
You could probably also do this using javascript and the select2_init hook to alter the select2 settings https://www.advancedcustomfields.com/resources/adding-custom-javascript-fields/
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!
ACF’s Repeater field is a versatile solution for repeating content in #WordPress.
— Advanced Custom Fields (@wp_acf) December 29, 2022
What’s your favorite use case for the Repeater field?
What’s the weirdest thing you’ve ever used it for?
Let us know!👇
© 2023 Advanced Custom Fields.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.