Support

Account

Home Forums ACF PRO ACF the WP-API and a unique repeater row id

Solved

ACF the WP-API and a unique repeater row id

  • Hi,

    This is a sort of advanced topic. I am using ACF and consuming the data via the WP-API. I was wondering if there was a way to have a repeater create a unique ID for each row. I did not see it in the field types. It would be perhaps a GUID or some auto-number. I know it exists in the WP Meta data but it is not exposed in the API.

    For example, the JSON returns a repeater as this

    "acf": {
    "dt_result": [
    {
    "result_title": "Program Identity",
    "result_text": "Here is some copy",
    },
    {
    "result_title": "No Program Identity",
    "result_text": "Here is some other copy"
    }
    ],

    Is it possible to have ACF return this

    “acf”: {
    “dt_result”: [
    {
    “id”: “GUID”,
    “result_title”: “Program Identity”,
    “result_text”: “Here is some copy”,
    },
    {
    “id”: “GUID2”,
    “result_title”: “No Program Identity”,
    “result_text”: “Here is some other copy”
    }
    ],

    The reasons for this should be obvious to anyone who has dealt with data.

    Paul

  • This is what you’re looking for: https://github.com/philipnewcomer/ACF-Unique-ID-Field 🙂

    Just install it like you would any other plugin and then you should be able to add a unique ID field to any row, group etc…

  • Very nice! This worked great. Of course you can install without composer by adding this to your functions file.

    // Repeater unique ID in a folder called functions in my theme
    require_once(‘functions/ACF_Field_Unique_ID.php’);

    PhilipNewcomer\ACF_Unique_ID_Field\ACF_Field_Unique_ID::init();

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

The topic ‘ACF the WP-API and a unique repeater row id’ is closed to new replies.