Created
May 29, 2018 11:36
-
-
Save mustardBees/1ca6c035b6861b370fd9c7813b5667df to your computer and use it in GitHub Desktop.
ACF gallery field. Merge serialized arrays php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div id="main-content" class="is_fullwidth home-template"> | |
<div class="container"> | |
<div class="row"> | |
<div class="col-xs-12"> | |
<form method="post"> | |
<p> | |
<textarea name="galleries" style="width: 500px; height:200px;"><?php echo ( isset( $_POST['galleries'] ) && ! empty( $_POST['galleries'] ) ) ? stripslashes( $_POST['galleries'] ) : ''; ?></textarea> | |
</p> | |
<p> | |
<button type="submit">Go Go Go!</button> | |
</p> | |
</form> | |
</div> | |
</div> | |
</div> | |
</div> | |
<?php | |
if ( isset( $_POST['galleries'] ) && ! empty( $_POST['galleries'] ) ) { | |
$galleries = trim( stripslashes( $_POST['galleries'] ) ); | |
$galleries_split = $skuList = explode( PHP_EOL, $galleries ); | |
$galleries_merged = array(); | |
foreach ( $galleries_split as $gallery ) { | |
$gallery = trim($gallery); | |
$array = maybe_unserialize( $gallery ); | |
$galleries_merged = array_merge( $galleries_merged, $array ); | |
} | |
debug($galleries_merged); | |
debug( maybe_serialize( $galleries_merged ) ); | |
} | |
?> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment