Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_action('save_post', 'hhs_repeatable_meta_box_save');
- function hhs_repeatable_meta_box_save($post_id)
- {
- if (!isset($_POST['hhs_repeatable_meta_box_nonce']) ||
- !wp_verify_nonce($_POST['hhs_repeatable_meta_box_nonce'], 'hhs_repeatable_meta_box_nonce')
- )
- return;
- if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)
- return;
- if (!current_user_can('edit_post', $post_id))
- return;
- $old = get_post_meta($post_id, 'repeatable_fields');
- $new = array();
- $names = $_POST['name'];
- $dates = $_POST['date'];
- $texts = $_POST['text'];
- $images = $_POST['image'];
- $count = count($names);
- for ($i = 0; $i < $count; $i++) {
- if ($names[$i] != '') :
- $new[$i]['name'] = $names[$i];
- if ($dates[$i] != '') {
- $new[$i]['date'] = $dates[$i];
- };
- if ($texts[$i] != '') {
- $new[$i]['text'] = $texts[$i];
- };
- if ($images[$i] != '' ) {
- $new[$i]['image'] = $images[$i];
- };
- endif;
- if (!empty($new) && $new != $old)
- update_post_meta($post_id, 'repeatable_fields', $new);
- elseif (empty($new) && $old)
- delete_post_meta($post_id, 'repeatable_fields', $old);
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement