Bulk Edit Issue.

Hi,

someone gave me a help on this before I think it’s 1yr ago but I forgot his name and the original thread is from the old forum…

EDIT: here’s the old forum link: http://themeforest.net/forums/thread/remove-auto-assign-for-custom-fields/132163

 if ((defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) || (defined('DOING_AJAX') && DOING_AJAX)) return;
    			if ( 'page' == isset($_POST['post_type']) ) { if ( !current_user_can( 'edit_page', $post_id ) ) return;
    			} else { if ( !current_user_can( 'edit_post', $post_id ) ) return; }

    			$arch_fields = array( 'bgslide', 'bgimage' );

    			foreach ($arch_fields as $arch_value) {
    	         if( isset($arch_value) ) :

    	            $arch_new = false;
    	            $arch_old = get_post_meta( $post_id, $arch_value, true );

    	            if ( isset( $_POST[$arch_value] ) ) :
    	               $arch_new = $_POST[$arch_value];
    	           	endif;

    	            if ( isset( $arch_new ) && '' == $arch_new && $arch_old ) :
    	               delete_post_meta( $post_id, $arch_value, $arch_old );
    	            elseif ( false === $arch_new || !isset( $arch_new ) ) :
    	            	delete_post_meta( $post_id, $arch_value, $arch_old );
    	            elseif ( isset( $arch_new ) && $arch_new != $arch_old ) :
    	            	update_post_meta( $post_id, $arch_value, $arch_new );
    	           	elseif ( ! isset( $arch_old ) && isset( $arch_new ) ) :
    	               add_post_meta( $post_id, $arch_value, $arch_new );
    	            endif;

    	         endif;
    	      }

the issue on this code is that it will remove the custom fields data when save as bulk edit… can anyone help me fix this?

Thank you in advance…

anyone use this code before? I need help :slightly_smiling:

I think this code won’t work on bulk edit… it will simply remove other data fields once bulk edit… It works fine if not using foreach…

I modified the code and now the issue is the checkbox, it is not saving… all fields saved fine except on the checkbox…

$arch_old = get_post_meta( $post_id, $arch_value, true );

if( isset($_POST[$arch_value]) && $_POST[$arch_value] != $arch_old ) :
   update_post_meta( $post_id, $arch_value, $_POST[$arch_value] );		
elseif( isset($_POST[$arch_value]) && '' == $_POST[$arch_value] && $arch_old ) :
   delete_post_meta( $post_id, $arch_value, $arch_old );
endif;

anyone can help?
Thanks

even if I added the default save code…

update_post_meta( $post_id, 'arch_hide', $_POST['arch_hide'] );

still checkbox is not saving properly… other fields saved fine… and my checkbox code is this

if( $arch_hide == "on" ) : $checked = 'checked="checked"';	
else : $checked = ''; 
endif;

<input type="checkbox" name="arch_hide" id="arch_hide" <?php echo $checked; ?> />

this issue only appears when bulk edit used…

Thanks