Home Forums Feedback Explain how acf_add_options_page() post_id works


Explain how acf_add_options_page() post_id works

  • Hi,

    I’m playing with options page and polylang translations (here’s a topic about it)

    It doesn’t work out of the box, so I was looking for a solution. I knew that I can register an options page with a custom id, but I thought it works slightly different than it really works.

    I thought I can either provide an ID of existing page or a 'options' string. I didn’t knew that it could be any string!

    So this is a great solution for me… but IMO it should be explained better in the documentation.

  • @wube, what do you mean you and supply “any string”. Where are the values saved if you supply something other than a post ID or ‘options’. Just curious what I’m missing.

  • I should have been more specific. Here’s the explanation:

    This is how I used to register options pages:

        'page_title' => __('Options page', 'textdomain'),
        'menu_title' => __('Options page', 'textdomain'),
        'menu_slug' => 'options-page-slug'

    This is what I refer to in the previous post:

        'page_title' => __('Options page', 'textdomain'),
        'menu_title' => __('Options page', 'textdomain'),
        'menu_slug' => 'options-page-slug',
        'post_id' => 'custom-id-as-a-string' // A custom string

    Thanks to this feature I don’t need to prefix custom fields names with a unique prefix, in order to avoid conflicts. I can simply register multiple options pages with a different post_id parameter.

    Then I’m able to get custom fields like this:

    get_field('field_name', 'custom-id-as-a-string');

    Direct answer to your question:
    Fields are saved in the wp_options table, but their names are prefixed with a value of the post_id attribute. So if the field name is field_name and the options page post_id attribute value is custom-id-as-a-string then the database entry is custom-id-as-a-string_field_name.

    I think it should be clearly explained in the documentation. It is said in the documentation that the post_id could be an integer or a string, but it doesn’t explain that it can be any string. Users might think that the string should be a post slug or something… This is exactly what I thought before i started to play with custom strings.

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

The topic ‘Explain how acf_add_options_page() post_id works’ is closed to new replies.