Support

Account

Home Forums Add-ons Options Page Options Page Fields Need Unique Names

Helping

Options Page Fields Need Unique Names

    • retlive

    • November 15, 2018 at 9:04 am

    Bug: Options Page Add-on Field Names Must be Unique

    Problem Observed: When I used the same field names for different field groups with the options page add-on, changes to one field group would overwrite content in other field groups.

    Possible Solution: While the wp_options table does store unique field IDs for each field, ACF doesn’t seem to use the unique field ID. Maybe you could append the field ID to option_name in wp_options, and possibly use a third argument for getting the value with the_field, like:
    the_field( 'field_name', 'option', 'field_ID' )

  • In the case of options pages, acf is just a wrapper for the WP functions get_option() and update_option(). There is nothing built into these functions that allows for duplicate field names. In fact, the database is set up so that the “option_name” value must be unique.

    There is a work-a-round for this that is not well known. When saving options ACF prefixes the option name with “options_”. You can alter this by altering the post ID used for the options page. This is one of the settings when adding an options page. For example, if you used the post ID of one page or “theme_options” and the post ID of “some_other_options” for a second page and both options pages have a field name “some_field_name” ACF will store one at “theme_options_some_field_name” and the other at “some_other_options_some_field_name”

    You just need to give the correct post ID when getting these options, instead of get_field('my_field', 'options') you would do get_field('my_field', 'theme_options')

Viewing 2 posts - 1 through 2 (of 2 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.