Home › Forums › Add-ons › Options Page › Extend conditional logic to be set from options page › Reply To: Extend conditional logic to be set from options page
What you are looking to do is to dynamically set the location rules for field groups based on the values of an options page. This can be done. If you are not using JSON files you can use the acf/load_field_group hook
add_filter('acf/load_field_group', 'your_function_name', 20);
function your_function_name($group) {
if ($group['key'] == 'group_YOUR_GROUP_KRY')) {
}
}
if you are using json files, of just to be sure, you should use the acf/validate_field_group hook. The above hook is not called when loading json files.
add_filter('acf/validate_field_group', 'your_function_name', 20);
function your_function_name($group) {
if ($group['key'] == 'group_YOUR_GROUP_KRY')) {
}
}
In your filter you can check your options and set the location rules dynamically based on your checks. For examples of how the location rules work I would set some location rules in ACF and do an export to see how this value of the group needs to be added.
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.