• Resolved devcri

    (@devcri)


    Hi,
    thank you for this great plugin! I discovered a little problem with ACF relation fields. I have an ACF Field defining a 1 to many relation to posts of the same custom post type.

    I can see the field in JSON, but it shows an empty array (I double checked that it is not empty in the WordPress Backend):
    JSON:
    “acf”: {
    “field_with_relation_set”: [],

    If the field is not set (no relation to other posts) it shows up like this:
    JSON:
    “acf”: {
    “field_with_relation_set”: [],

    Is there any setting that I am missing or do relations not work?

    Cheers!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter devcri

    (@devcri)

    Update:
    I discovered your ACF to REST API Recursive Plugin (https://github.com/airesvsg/acf-to-rest-api-recursive) and installed it. Than I integrated your code snippet (from https://github.com/airesvsg/acf-to-rest-api/issues/223#issuecomment-378610482) into my theme:

    add_filter( 'acf/rest_api/recursive/types', function( $types ) {
      $slugs = (array) cptui_get_post_type_slugs();
    
      $types += array_combine( $slugs, $slugs );
    
      return $types;
    } );
    

    But the relation field still remains empty, showing only the brackets []. Any help appreciated.

    Thread Starter devcri

    (@devcri)

    SOLUTION:
    I found the solution to this problem. For anyone that is interested: the plugin works fine and you don’t need the recursive plugin in this case. After trying a lot of scripts from GitHub and also giving another plugin (ACF to WP-API) a try I concluded that the relationship field always comes back as empty array []. So I checked the field configuration for the relationship field in ACF and found a setting “Return Format” (Frontend). In my case it was configured to “Post Objects”. I changed it to “Post IDs”. After changing it everything in the backend stays the same, but in the JSON File I finally see the IDs of the related custom post types. Hope this helps someone with the same problem in the future.

    mulli.bahr

    (@mullibahr)

    Thanks for sharing! I shall try it.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘ACF Relation shows up as empty array in JSON’ is closed to new replies.