@@ -37,22 +37,56 @@ function fetch_project ($data) {
37
37
$ post ->carousels = carbon_get_post_meta ($ post ->ID , 'carousels ' );
38
38
if (count ((array )$ post ->carousels ) > 0 ) {
39
39
foreach ($ post ->carousels as $ key => &$ carousel ) {
40
- $ carousel ['description ' ] = wpautop ($ carousel ['description ' ]);
41
- if (count ($ carousel ['images ' ]) > 0 ) {
42
- foreach ($ carousel ['images ' ] as $ key => &$ image ) {
43
- $ image ['description ' ] = wpautop ($ image ['description ' ]);
44
- $ image ['data ' ] = get_image_data ($ image ['id ' ]);
40
+ if ($ carousel ['_type ' ] === 'gallery ' ) {
41
+ foreach ($ carousel ['gallery ' ] as $ key => &$ asset ) {
42
+ $ asset_id = $ asset ;
43
+ $ asset = get_asset_data ($ asset_id );
44
+ $ asset ['id ' ] = $ asset_id ;
45
+ }
46
+ $ carousel ['assets ' ] = $ carousel ['gallery ' ];
47
+ unset($ carousel ['gallery ' ]);
48
+ }
49
+ if ($ carousel ['_type ' ] === 'assets ' ) {
50
+ foreach ($ carousel ['assets ' ] as $ key => &$ asset ) {
51
+ $ asset ['caption ' ] = wpautop ($ asset ['caption ' ] ?? '' );
52
+ $ asset = array_merge ($ asset , get_asset_data ($ asset ['id ' ]));
53
+ }
54
+ }
55
+ if ($ carousel ['_type ' ] === 'complex ' ) {
56
+ $ carousel ['description ' ] = wpautop ($ carousel ['description ' ]);
57
+ if (count ($ carousel ['assets ' ]) > 0 ) {
58
+ // Only take the first item from the array.
59
+ $ carousel ['assets ' ] = $ carousel ['assets ' ][0 ];
60
+ unset($ carousel ['assets ' ][0 ]);
61
+
62
+ // Set asset data.
63
+ if ($ carousel ['assets ' ]['_type ' ] === 'complex ' ) {
64
+ foreach ($ carousel ['assets ' ]['complex ' ] as $ key => &$ asset ) {
65
+ $ asset ['caption ' ] = wpautop ($ asset ['caption ' ] ?? '' );
66
+ $ asset = array_merge ($ asset , get_asset_data ($ asset ['id ' ]));
67
+ }
68
+ $ carousel ['assets ' ] = $ carousel ['assets ' ]['complex ' ];
69
+ }
70
+ if ($ carousel ['assets ' ]['_type ' ] === 'gallery ' ) {
71
+ foreach ($ carousel ['assets ' ]['gallery ' ] as $ key => &$ asset ) {
72
+ $ asset_id = $ asset ;
73
+ $ asset = get_asset_data ($ asset_id );
74
+ $ asset ['id ' ] = $ asset_id ;
75
+ }
76
+ $ carousel ['assets ' ] = $ carousel ['assets ' ]['gallery ' ];
77
+ }
78
+ unset($ carousel ['assets ' ]['_type ' ]);
45
79
}
46
80
}
47
81
}
48
82
}
49
83
50
84
// Add images from carbon fields.
51
- $ post ->images = carbon_get_post_meta ($ post ->ID , 'images ' );
52
- if (count ((array )$ post ->images ) > 0 ) {
53
- foreach ($ post ->images as $ key => &$ image ) {
54
- $ image [ ' description ' ] = wpautop ($ image [ ' description ' ] );
55
- $ image [ ' data ' ] = get_image_data ( $ image ['id ' ]);
85
+ $ post ->assets = carbon_get_post_meta ($ post ->ID , 'assets ' );
86
+ if (count ((array )$ post ->assets ) > 0 ) {
87
+ foreach ($ post ->assets as $ key => &$ asset ) {
88
+ $ asset [ ' caption ' ] = wpautop ($ asset [ ' caption ' ] ?? '' );
89
+ $ asset = array_merge ( $ asset , get_asset_data ( $ asset ['id ' ]) );
56
90
}
57
91
}
58
92
0 commit comments