Home Forums General Issues Add my custom location rules on plugin activation Reply To: Add my custom location rules on plugin activation

  • I’m sure there is a way to prevent other field groups from ever showing up on your custom post type by creating custom match rules acf/location/rule_match/... it’s actually an interesting question.

    I like interesting questions.

    This is possible in ACF version >= 5.3.5

    You can filter the options sent to the rule match filter like this

    add_filter('acf/location/screen', 'add_group_key_to_location_args', 10, 2);
    function add_group_key_to_location_args($args, $group) {
      $args['group_key'] = $group['key'];
      return $args;

    That will add the current field group id to the options used for the acf/location/rule_match/... filter. Then you can create a filter for specific rule match types to only allow your field group.

    add_filter('acf/location/rule_match/post_type', 'prevent_all_groups_but_mine', 20, 3);
    function prevent_all_groups_but_mine($match, $rule, $options) {
      if ($options['post_type'] == 'your-post-type' &&
          $options['group_key'] != 'group_yourGroupKey') {
        return false;
      return $match;

    The main problem is that you’ll need to create a rule match filter for every location rule where you want to prevent other groups and you won’t be able to account for custom rules that other people create.

    The other problem that I can see is ensuring that there would never be any reason to add additional rule groups to your post type. What it someone wants to extend your plugin? Or add fields to what is displayed when viewing the posts of your post type?