---
description: lưu trữ mảng trong một trường tùy chỉnh
---

# store arrays in a custom field in post (ok)

```
// header.php
<?php  
	echo '<pre>';
		var_export(get_post_meta(1,'customfield1'));
	echo '</pre>';
?>
```

```
// function.php
// Add a custom action on save post so we can convert our custom format
add_action( 'save_post', 'smyles_save_post_format_custom_field');
function smyles_save_post_format_custom_field(){
  $metas = $_POST['meta'];
  $post_id = get_the_ID();
  foreach ($metas as $key => $value) {
  	$custom_field = explode(',', $value['value']);
  	update_post_meta($post_id,$metas[$key]['key'],$custom_field);
  }
}
```

![](https://2370029328-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LWPtKFbhw0XehxVuoiZ%2F-M8huR8q4u9R48LMQ5ij%2F-M8hvh5h9v_kBUTDfyYG%2F14.png?alt=media\&token=41112217-3928-4acf-884e-278977d9bab1)

![](https://2370029328-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LWPtKFbhw0XehxVuoiZ%2F-M8huR8q4u9R48LMQ5ij%2F-M8hvjq5p-7w_ZDtaTis%2F15.png?alt=media\&token=0d1427c1-638c-477f-b605-7d8aa8fcdb60)

![](https://2370029328-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LWPtKFbhw0XehxVuoiZ%2F-M8huR8q4u9R48LMQ5ij%2F-M8hvlwTeQ1FvxjF2pSd%2F16.png?alt=media\&token=08ba6d9a-a953-4c0a-9f65-1e209eddd13f)
