wp-graphql-gutenberg-acf icon indicating copy to clipboard operation
wp-graphql-gutenberg-acf copied to clipboard

Problem with ACF repeater fields and post objects inside custom post type

Open orjanb-ne opened this issue 6 years ago • 1 comments

I created a custom block and added a few custom fields with ACF, when using the block inside a post or page the data looks fine. But when using the EXACT same custom fields inside a custom post type the post object inside the repeater is returning the same ID for all posts.

This is my ACF: [ { "key": "group_5d6e50edc46a8", "title": "Timeline", "fields": [ { "key": "field_5d6e521fd60ca", "label": "Timeline row", "name": "acf_timeline_row", "type": "repeater", "instructions": "", "required": 0, "conditional_logic": 0, "wrapper": { "width": "", "class": "", "id": "" }, "show_in_graphql": 1, "collapsed": "", "min": 0, "max": 0, "layout": "block", "button_label": "Add row", "sub_fields": [ { "key": "field_5d6e5270d60cb", "label": "Date", "name": "acf_timeline_date", "type": "text", "instructions": "", "required": 1, "conditional_logic": 0, "wrapper": { "width": "", "class": "", "id": "" }, "show_in_graphql": 1, "default_value": "", "placeholder": "", "prepend": "", "append": "", "maxlength": "" }, { "key": "field_5d6e52b2d60cc", "label": "Content", "name": "acf_timeline_content", "type": "post_object", "instructions": "", "required": 1, "conditional_logic": [ [ { "field": "field_5d6e5270d60cb", "operator": "!=empty" } ] ], "wrapper": { "width": "", "class": "", "id": "" }, "show_in_graphql": 1, "post_type": [ "post" ], "taxonomy": "", "allow_null": 0, "multiple": 1, "return_format": "object", "ui": 1 } ] } ], "location": [ [ { "param": "block", "operator": "==", "value": "acf\/timeline" } ], [ { "param": "post_type", "operator": "==", "value": "custom_timeline" } ] ], "menu_order": 0, "position": "normal", "style": "default", "label_placement": "top", "instruction_placement": "label", "hide_on_screen": "", "active": true, "description": "", "show_in_graphql": 1, "graphql_field_name": "acfTimeline" } ]

This is my functions.php: add_action('acf/init', 'my_acf_init'); function my_acf_init() { acf_register_block(array( 'name' => 'timeline', 'title' => __('Timeline'), 'description' => __('A custom timeline block.'), 'render_callback' => 'my_acf_timeline_block_render_callback', 'category' => 'embed', 'icon' => 'pressthis', 'keywords' => array( 'timeline', 'posts' ), )); } function custom_timeline_init() { $labels = array( 'name' => __('Timeline'), 'singular_name' => __('Timeline'), 'all_items' => __('All Timelines'), 'add_new_item' => __('Add new Timeline'), 'edit_item' => __('Edit Timeline'), 'new_item' => __('New Timeline'), 'view_item' => __('View Timeline'), 'search_items' => __('Search in Timelines'), 'not_found' => __('No Timeline found'), 'not_found_in_trash' => __('No Timeline found in trash'), ); $args = array ( 'labels' => $labels, 'show_ui' => true, 'public' => true, 'menu_icon' => 'dashicons-pressthis', 'show_in_rest' => true, 'show_in_graphql' => true, 'hierarchical' => false, 'capability_type' => 'post', 'graphql_single_name' => 'Timeline', 'graphql_plural_name' => 'Timelines', 'supports' => array( 'custom-fields', 'title', 'revisions' ) ); register_post_type( 'custom_timeline', $args); } add_action('init', 'custom_timeline_init');

The "content" field is used to link post objects. I tried to change post objects in the custom post type and the block (used in a post), but the postId is still "1" in the custom post type.

This is my query: query GET_SOMETHING { timelineBy(timelineId: 682) { acfTimeline { acfTimelineRow { acfTimelineDate acfTimelineContent { ... on Post { postId } } } } } postBy(postId: 314) { blocks { ... on AcfTimelineBlock { acf { acf_timeline_row { acf_timeline_date acf_timeline_content { postId } } } } } } }

And my response: { "data": { "timelineBy": { "acfTimeline": { "acfTimelineRow": [ { "acfTimelineDate": "10000 BC", "acfTimelineContent": { "postId": 1 } }, { "acfTimelineDate": "7000 BC", "acfTimelineContent": { "postId": 1 } } ] } }, "postBy": { "blocks": [ { "acf": { "acf_timeline_row": [ { "acf_timeline_date": "10000 BC", "acf_timeline_content": [ { "postId": 683 } ] }, { "acf_timeline_date": "7000 BC", "acf_timeline_content": [ { "postId": 715 } ] } ] } } ] } } }

orjanb-ne avatar Jan 09 '20 10:01 orjanb-ne

The problem only occurs when I enable "Select multiple values".

orjanb-ne avatar Jan 09 '20 11:01 orjanb-ne