skip to Main Content

We’re encountering recurring issues with Advanced Custom Fields (ACF) in our backend-driven WordPress application. After a recent version upgrade, the ACF-to-REST plugin broke, which prompted me to explore ACF’s built-in endpoint exposure.

I’ve successfully set up ACF’s own endpoint, but I’m facing a problem with repeater fields. When accessing the endpoint, the fields are assigned random keys, making it difficult to work with the data as expected. Here’s a screenshot below illustrating the issue.

  • Has anyone else experienced similar issues with ACF’s built-in
    endpoint and repeater fields after an upgrade?

    2.Are there any known solutions or workarounds for maintaining stable field keys when using ACF’s built-in endpoint?

    1. Alternatively, should we consider exploring other solutions? I appreciate any insights or guidance on how to resolve
      this problem and ensure the sustainability of our backend-driven
      application with ACF.

enter image description here

2

Answers


  1. Chosen as BEST ANSWER

    My mistake was having duplicate field groups. When I removed one the problem disappeared.


  2. You should use a custom REST API endpoint that will return exactly what you want

    Here is the short example you can start with:

    add_action( 'rest_api_init', function () {
      register_rest_route( 'acfroute/v1', '/resource/', array(
        'methods' => 'GET',
        'callback' => 'acf_endpoint',
      ) );
    } );
    
    function acf_endpoint( $data ) {
      $posts = get_posts( array(
        'post_type' => 'post',
      ) );
    
      foreach ( $posts as $post ) {
        // Get ACF fields here as you need 
      }
    
      return $formatted_data;
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search