Support

Account

Home Forums ACF PRO Connect option page to field group via PHP

Solved

Connect option page to field group via PHP

  • Hi, so I am trying to solve this issue:

    1) every user has custom option pages via “{$userlogin}-global-{$lang}” (post_id)
    2) userlogin is current user login, and lang is based on set of languages allowed for specific user (can be 1, or can be 20)

    How do I connect my field group called “Options” to these options pages? Cause I can’t set it up for “all option pages” (no option in rules https://ibb.co/PZpJ1jj).

    Can I connect somehow “key” of the field group for created option page via PHP?

  • You need to do this with PHP. There is an undocumented filter

    
    add_filter('acf/validate_field_group', 'special_location_rules', 20, 1);
    function special_location_rules($group) {
      if ($group['key'] != 'YOUR FIELD GROUP KEY HERE') {
        return;
      }
      // set conditional logic
      return $group;
    }
    

    Create a field group with several rule groups (ORs) and export it so that you can see how $group['conditional_logic'] is organized. It is a nested array that holds the AND/OR logic.

  • Yes, I tried this, but as support told me yesterday, it’s kinda impossible to do in current stage of development.

    My point was, that every user see option page based on “user_login”. Which works, but than there pre_get_posts problem, admin can’t edit it etc.

  • I would create a CPT rather than options pages. Having an options page for every user seems the wrong use for options pages.

  • Yes, you are totally right. After further testing I already found out, that CPT are better for this type of job 🙂

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

You must be logged in to reply to this topic.