Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
ACF gallery field. Merge serialized arrays php
<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
You can’t perform that action at this time.