@@ -315,11 +315,13 @@ function render_field( $field ) {
315
315
316
316
<?php echo $ before_fields ; ?>
317
317
318
+
318
319
<?php
319
320
// prevent childbuilder field from creating multiple conditional logic items for each row
320
321
$ sub_field = $ field ['sub_fields ' ][0 ];
321
322
$ sub_field ['conditional_logic ' ] = 0 ;
322
-
323
+ $ sub_field ['wrapper ' ]['class ' ] = $ sub_field ['wrapper ' ]['class ' ] . ($ i === 'acfcloneindex ' ? 'acf-child-post-field-hide ' : '' );
324
+
323
325
$ acf_child_field_post_id = '' ;
324
326
// add value
325
327
if ( isset ( $ row [$ sub_field ['key ' ]] ) ) {
@@ -333,93 +335,106 @@ function render_field( $field ) {
333
335
$ sub_field ['value ' ] = $ acf_child_field_post_id ;
334
336
// update prefix to allow for nested values
335
337
$ sub_field ['prefix ' ] = "{$ field ['name ' ]}[ {$ i }] " ;
336
-
337
- // render input
338
- acf_render_field_wrap ( $ sub_field , $ el );
339
-
340
-
341
- $ post = get_post ( $ acf_child_field_post_id );
342
-
343
- if ( $ field ['include_title_editor ' ] ) {
344
- acf_render_field_wrap ( acf_get_valid_field ( array (
345
- 'name ' => "{$ field ['name ' ]}[ {$ i }][post_data][post_title] " ,
346
- 'label ' => 'Title ' ,
347
- 'type ' => 'text ' ,
348
- 'value ' => $ post ->post_title ,
349
- 'required ' => true
350
- ) ), $ el );
338
+ if ($ acf_child_field_post_id ){
339
+ $ post = get_post ( $ acf_child_field_post_id );
340
+ } else {
341
+ $ post = new stdClass ();
342
+ $ post ->post_title = '' ;
343
+ $ post ->post_content = '' ;
344
+ $ post ->post_excerpt = '' ;
345
+ $ post ->ID = '' ;
351
346
}
347
+
348
+ ?>
349
+ <div class="acf-field-list-title">
350
+ <span class="acf-field-list-title-span"><?php echo $ post ->post_title ; ?> </span>
351
+ </div>
352
+
353
+ <?php
354
+ // render input
355
+ acf_render_field_wrap ( $ sub_field , $ el );
356
+
357
+
358
+ if ( $ field ['include_title_editor ' ] ) {
359
+ acf_render_field_wrap ( acf_get_valid_field ( array (
360
+ 'name ' => "{$ field ['name ' ]}[ {$ i }][post_data][post_title] " ,
361
+ 'label ' => 'Title ' ,
362
+ 'type ' => 'text ' ,
363
+ 'value ' => $ post ->post_title ,
364
+ 'required ' => true
365
+ ) ), $ el );
366
+ }
352
367
353
- if ( $ field ['include_content_editor ' ] ) {
354
- acf_render_field_wrap ( acf_get_valid_field ( array (
355
- 'name ' => "{$ field ['name ' ]}[ {$ i }][post_data][post_content] " ,
356
- 'label ' => __ ( 'Post Content ' , 'acf_child_post_field ' ),
357
- 'type ' => 'wysiwyg ' ,
358
- 'value ' => $ post ->post_content ,
359
- 'required ' => false
360
- ) ), $ el );
361
- }
368
+ if ( $ field ['include_content_editor ' ] ) {
369
+ acf_render_field_wrap ( acf_get_valid_field ( array (
370
+ 'name ' => "{$ field ['name ' ]}[ {$ i }][post_data][post_content] " ,
371
+ 'label ' => __ ( 'Post Content ' , 'acf_child_post_field ' ),
372
+ 'type ' => 'wysiwyg ' ,
373
+ 'value ' => $ post ->post_content ,
374
+ 'required ' => false
375
+ ) ), $ el );
376
+ }
362
377
363
- if ( $ field ['include_excerpt_editor ' ] ) {
364
- acf_render_field_wrap ( acf_get_valid_field ( array (
365
- 'name ' => "{$ field ['name ' ]}[ {$ i }][post_data][post_excerpt] " ,
366
- 'label ' => __ ( 'Excerpt ' , 'acf_child_post_field ' ),
367
- 'type ' => 'textarea ' ,
368
- 'value ' => $ post ->post_excerpt ,
369
- 'required ' => false
370
- ) ), $ el );
371
- }
378
+ if ( $ field ['include_excerpt_editor ' ] ) {
379
+ acf_render_field_wrap ( acf_get_valid_field ( array (
380
+ 'name ' => "{$ field ['name ' ]}[ {$ i }][post_data][post_excerpt] " ,
381
+ 'label ' => __ ( 'Excerpt ' , 'acf_child_post_field ' ),
382
+ 'type ' => 'textarea ' ,
383
+ 'value ' => $ post ->post_excerpt ,
384
+ 'required ' => false
385
+ ) ), $ el );
386
+ }
372
387
373
- if ( $ field ['include_featured_image_editor ' ] ) {
374
- acf_render_field_wrap ( acf_get_valid_field ( array (
375
- 'name ' => "{$ field ['name ' ]}[ {$ i }][post_data][featured_image] " ,
376
- 'label ' => __ ( 'Featured Image ' , 'acf_child_post_field ' ),
377
- 'type ' => 'image ' ,
378
- 'value ' => get_post_thumbnail_id ( $ post ->ID ),
379
- 'required ' => false
380
- ) ), $ el );
381
- }
388
+ if ( $ field ['include_featured_image_editor ' ] ) {
389
+ acf_render_field_wrap ( acf_get_valid_field ( array (
390
+ 'name ' => "{$ field ['name ' ]}[ {$ i }][post_data][featured_image] " ,
391
+ 'label ' => __ ( 'Featured Image ' , 'acf_child_post_field ' ),
392
+ 'type ' => 'image ' ,
393
+ 'value ' => get_post_thumbnail_id ( $ post ->ID ),
394
+ 'required ' => false
395
+ ) ), $ el );
396
+ }
382
397
383
- foreach ( $ field ['acf_child_field_fields ' ] as $ child_field ):
398
+ foreach ( $ field ['acf_child_field_fields ' ] as $ child_field ):
384
399
385
- // prevent childbuilder field from creating multiple conditional logic items for each row
386
- if ( $ i !== 'acfcloneindex ' ) {
387
- $ child_field ['conditional_logic ' ] = 0 ;
388
- }
400
+ // prevent childbuilder field from creating multiple conditional logic items for each row
401
+ if ( $ i !== 'acfcloneindex ' ) {
402
+ $ child_field ['conditional_logic ' ] = 0 ;
403
+ }
389
404
390
405
391
- // add value
392
- if ( isset ( $ row ['acf_child_field_values ' ][$ child_field ['key ' ]] ) ) {
393
- // this is a normal value
394
- $ child_field ['value ' ] = $ row ['acf_child_field_values ' ][$ child_field ['key ' ]];
395
- } elseif ( isset ( $ child_field ['default_value ' ] ) ) {
406
+ // add value
407
+ if ( isset ( $ row ['acf_child_field_values ' ][$ child_field ['key ' ]] ) ) {
408
+ // this is a normal value
409
+ $ child_field ['value ' ] = $ row ['acf_child_field_values ' ][$ child_field ['key ' ]];
410
+ } elseif ( isset ( $ child_field ['default_value ' ] ) ) {
396
411
397
- // no value, but this sub field has a default value
398
- $ child_field ['value ' ] = $ child_field ['default_value ' ];
399
- }
412
+ // no value, but this sub field has a default value
413
+ $ child_field ['value ' ] = $ child_field ['default_value ' ];
414
+ }
400
415
401
416
402
- // update prefix to allow for nested values
403
- $ child_field ['prefix ' ] = "{$ field ['name ' ]}[ {$ i }] " ;
417
+ // update prefix to allow for nested values
418
+ $ child_field ['prefix ' ] = "{$ field ['name ' ]}[ {$ i }] " ;
404
419
405
420
406
- // render input
407
- acf_render_field_wrap ( $ child_field , $ el );
408
- ?>
421
+ // render input
422
+ acf_render_field_wrap ( $ child_field , $ el );
423
+ ?>
409
424
410
- <?php endforeach ; ?>
425
+ <?php endforeach ; ?>
411
426
412
- <?php echo $ after_fields ; ?>
427
+ <?php echo $ after_fields ; ?>
413
428
414
- <?php if ( $ show_remove ): ?>
415
- <td class="remove">
416
- <a class="acf-icon small acf-childbuilder-add-row" href="#" data-before="1" title="<?php _e ( 'Add row ' , 'acf_child_post_field ' ); ?> "><i class="acf-sprite-add"></i></a>
417
- <a class="acf-icon small acf-childbuilder-remove-row" href="#" title="<?php _e ( 'Remove row ' , 'acf_child_post_field ' ); ?> "><i class="acf-sprite-remove"></i></a>
418
- </td>
419
- <?php endif ; ?>
429
+ <?php if ( $ show_remove ): ?>
430
+ <td class="remove">
431
+ <a class="acf-icon small acf-childbuilder-add-row" href="#" data-before="1" title="<?php _e ( 'Add row ' , 'acf_child_post_field ' ); ?> "><i class="acf-sprite-add"></i></a>
432
+ <a class="acf-icon small acf-childbuilder-remove-row" href="#" title="<?php _e ( 'Remove row ' , 'acf_child_post_field ' ); ?> "><i class="acf-sprite-remove"></i></a>
433
+ </td>
434
+ <?php endif ; ?>
420
435
421
- </tr>
422
- <?php endforeach ; ?>
436
+ </tr>
437
+ <?php endforeach ; ?>
423
438
</tbody>
424
439
</table>
425
440
<?php if ( $ show_add ): ?>
@@ -735,11 +750,11 @@ function update_value( $value, $post_id, $field ) {
735
750
736
751
if ( $ field ['include_featured_image_editor ' ] ) {
737
752
$ image_id = isset ( $ row ['post_data ' ]['featured_image ' ] ) ? $ row ['post_data ' ]['featured_image ' ] : 0 ;
738
- update_post_meta ($ child_post_id , '_thumbnail_id ' , $ image_id);
753
+ update_post_meta ( $ child_post_id , '_thumbnail_id ' , $ image_id );
739
754
}
740
755
}
741
756
742
-
757
+
743
758
// modify name for save
744
759
$ sub_field ['name ' ] = "{$ field ['name ' ]}_ {$ i }_acf_child_field_post_id " ;
745
760
// update field
@@ -799,47 +814,29 @@ function update_value( $value, $post_id, $field ) {
799
814
}
800
815
801
816
/*
802
- * format_value()
803
- *
804
- * This filter is appied to the $value after it is loaded from the db and before it is returned to the template
805
- *
806
- * @type filter
807
- * @since 3.6
808
- * @date 23/01/13
809
- *
810
- * @param $value (mixed) the value which was loaded from the database
811
- * @param $post_id (mixed) the $post_id from which the value was loaded
812
- * @param $field (array) the field array holding all the field options
813
- *
814
- * @return $value (mixed) the modified value
815
- */
816
-
817
- /*
818
-
819
- function format_value( $value, $post_id, $field ) {
820
-
821
- // bail early if no value
822
- if( empty($value) ) {
823
-
824
- return $value;
825
-
826
- }
827
-
828
-
829
- // apply setting
830
- if( $field['font_size'] > 12 ) {
831
-
832
- // format the value
833
- // $value = 'something';
834
-
835
- }
836
-
837
-
838
- // return
839
- return $value;
840
- }
841
-
842
- */
817
+ * format_value()
818
+ *
819
+ * This filter is appied to the $value after it is loaded from the db and before it is returned to the template
820
+ *
821
+ * @type filter
822
+ * @since 3.6
823
+ * @date 23/01/13
824
+ *
825
+ * @param $value (mixed) the value which was loaded from the database
826
+ * @param $post_id (mixed) the $post_id from which the value was loaded
827
+ * @param $field (array) the field array holding all the field options
828
+ *
829
+ * @return $value (mixed) the modified value
830
+ */
831
+ function format_value ( $ value , $ post_id , $ field ) {
832
+
833
+ // bail early if no value
834
+ if ( empty ($ value ) ) {
835
+ return $ value ;
836
+ }
837
+
838
+ return wp_list_pluck ($ value , '_acf_child_field_post_id ' );
839
+ }
843
840
844
841
845
842
/*
0 commit comments