Support

Account

Home Forums Add-ons Options Page Extend conditional logic to be set from options page

Solved

Extend conditional logic to be set from options page

    • Ash

    • April 23, 2019 at 11:06 pm

    Hi,

    I’m looking for a way to set a global condition from an options page, which fields on posts can be shown/hidden via conditional logic.

    I want to set up something like this. On the options page it would have a true/false input that asks if you want to show social media options on posts.

    On the post then would show the social media fields IF the option was set to true on the ACF options page.

    I have searched around but I can’t seem to find anything on the topic. Can anyone help?

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

    • Ash

    • April 29, 2019 at 8:15 pm

    @hube2 Thanks. I will give it a go

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.

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.