Home Forums Bug Reports Update field with wrong post id value


Update field with wrong post id value

  • Tested on WP 5.4.2, ACF PRO 5.9.3

    I have simple page views tracker based on $page_id numeric value.
    If I try to change $post_id variable:

    $post_id = 'some_custom_text';
    $updated_views_key = acf_get_field_key('user_views', $post_id);
    $updated_views = get_field($updated_views_key, $post_id) + 1;
    update_field($updated_views_key, $updated_views, $post_id);

    update_field function still returns success, but in wp_option table 2 new fields are created with option names: ‘some_custom_text_user_views’ and’_some_custom_text_user_views’.

    Is it ok, if any custom text instead of numeric id or ‘option’ (reserved value for Option pages) creates new field in options table, no mater if it’s needed or not?

  • Not sure exactly what you are looking for.

    But, yes, if you use “some_text” then ACF will create an option value using the field name and prepended with “some_text_”.

    When you create an options page, the default $post_id is “options” and all fields saved on that options page will be “options_{$field_name}”

    You can specify a different “post_id” value when creating an options page, for example I can create an options page and specify that the post_id is “theme_options”. ACF will save all the values in the options table prepended with “theme_options_” and when I want to get the field I can use get_field('my-field-name', 'theme_options")

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

You must be logged in to reply to this topic.