Been having issues with getting a 500 error. Sometimes a change is saved, usually not. I've output the $key/$values to verify it's reaching the function and foreach. The output is the first key/value pair over and over...
I'm approaching this this way because I will have an unknown number of "officers" that will be output as a custom post type.
$name = 'officer' . '-' . $officer_id . '-' . $count;
?>
<label for="<?php echo $name; ?>">Officer #<?php echo $count; ?></label>
<input type="text" name="<?php echo $name; ?>" value="<?php echo $officer_info[0]->post_title; ?>">
<br />
<?php
$count++;
I tried entering officers as an array:
$name = 'officer' . '-' . $officer_id . '-' . $count;
?>
<label for="['<?php echo $name; ?>']">Officer #<?php echo $count; ?></label>
<input type="text" name="<?php echo $name; ?>" value="<?php echo $officer_info[0]->post_title; ?>">
With the id as the key, no change.
I've tried continue if 'officer' isn't in the $key with no change. I tried 'pre_post_update' instead of 'save_post' with no change. I've added priority and number (10, 2) of variables with no change.
add_action( 'save_post', 'officers_onto_board_page_save', 10, 2 );
function officers_onto_board_page_save( $post_id ) {
global $wpdb;
// if our current user can't edit this post, bail
if( !current_user_can( 'edit_post' ) ) {
return;
}
foreach ($_POST as $key => $item) {
echo $key . ' , ' . $item;
if (strpos($key, 'officer') == 0) {
$parts = explode('-', $key);
$my_post = array(
'ID' => $parts[1],
'post_title' => $item
);
wp_update_post( $my_post );
}
}
}
Any suggestions/recommendations would be appreciated.
example response: _wpnonce , dc7a6eaea0_wpnonce , dc7a6eaea0_wpnonce , dc7a6eaea0_wpnonce , dc7a6eaea0_wpnonce , dc7a6eaea0_wpnonce , dc7a6eaea0_wpnonce , dc7a6eaea0_wpnonce , dc7a6eaea0 (over and over)