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!
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.