Support

Account

Home Forums General Issues Set rules per field?

Solving

Set rules per field?

  • I’ve been searching for over an hour can’t seem to find a solution…

    I know how to set up rules for the group, but what about for a specific field? I don’t want to create a bunch of separate groups for the same category of fields. In this case, I’m using it for SEO purposes. There are certain fields that I only want shown on the back end if the page is a child of a specific page.

    Basically, I don’t want to create a bunch of separate groups…just one group for SEO fields but I want to control what fields show based on specific conditions. Make sense? Is there any way to set rules for specific fields within groups?

  • No, there isn’t a way in ACF to set location rules for specific fields.

    But this can be accomplished using filters like this one https://www.advancedcustomfields.com/resources/acf-prepare_field/

    Using that filter you do your own PHP to decide if the field should be displayed or not and return the field if it should or return false if you don’t want the field shown.

  • Is there a working example of the code? The description makes it sound like it applies to fields displayed on the front end. I need this for the back end.

  • So far my workaround has been to create the group twice and setting rules to have them display only on the pages I want, etc. Was just hoping for a more elegant solution. Would be great if the at least the Pro version had something like that included where you can have a filter set on specific fields.

  • acf/prepare_field has nothing to do with displaying of values in the field, only the display of the field where it appears to allow values to be entered. This can be on the front end [acf_foem()] or in the admin.

    If ACF needed to check location rules for every field the admin would never finish loading. But like I said, you can do this for specific fields based on whatever criteria you need to create.

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

You must be logged in to reply to this topic.