Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mustardBees/1ca6c035b6861b370fd9c7813b5667df to your computer and use it in GitHub Desktop.
Save mustardBees/1ca6c035b6861b370fd9c7813b5667df to your computer and use it in GitHub Desktop.
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