Support » Plugin: ACF to WP-API » ACF not added to posts in relation field if included in two places

  • This happens under the following conditions:
    – there are more than one relationship fields on the same page
    – the same post is used as a value for two or more of these fields
    – the relationship field is set to return the post object

    Expected behaviour:
    ACFs are added to every instance of the post object in the API response

    Current behaviour:
    ACFs are only added to the first instance of the post object in the API response

    Origin of the issue:
    In the ‘setFields’ function, when ACFs are added to a post object, the post ID is saved in the ‘fieldIDStack’ property. When the same post object is encountered again, it is ignored as its ID is already on the ‘fieldIDStack property.

    Suggested solution:
    Instead of only saving the ID of post object in ‘fieldIDStack’, I would suggest to save the ACF data as well. When a post object is encountered a second time, the already saved ACF data can be added to the object instead of the post object being skipped altogether.

  • The topic ‘ACF not added to posts in relation field if included in two places’ is closed to new replies.