Last active
December 14, 2015 23:09
-
-
Save thefrosty/5163269 to your computer and use it in GitHub Desktop.
On each form submission I am saving an array in meta, and on form completion I am trying to update the meta. But since it's a multidimensional array I am trying to target only the current matching array to update "inactive" to "active". And a form completion might not be the last or current array. It could be completed at a later time.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function submit_form() { | |
$value = array( | |
'key' => '', // Array key? | |
'date' => date( get_option( 'date_format' ) . ' ' . get_option('time_format'), current_time( 'timestamp', 0 ) ), | |
'name' => $user_name, | |
'email' => $email, | |
'hash' => $hash, | |
'message' => esc_textarea( $_POST['commentText'] ), | |
'activated' => 'inactive', | |
); | |
add_post_meta( $post_id, '_my_custom_meta', $value, false ); | |
} | |
function complete_submit_form() { | |
$post_meta = get_post_meta( $post_id, '_my_custom_meta', false ); | |
//Prob need a foreach loop and find some key to update just the [activated] key | |
update_post_meta( $post_id, '_my_custom_meta', 'active', $post_meta[$key]['activated'] ); //?? | |
} | |
/** | |
* Post Meta array output: | |
Array | |
( | |
[0] => Array | |
( | |
[date] => March 12, 2013 7:20 pm | |
[name] => Austy Frosty | |
[email] => afrostyy@***.com | |
[hash] => f577349fad301a9e5d2304404a02f86a | |
[message] => Yo dawg! | |
[activated] => inactive | |
) | |
[1] => Array | |
( | |
[date] => March 13, 2013 12:18 pm | |
[name] => Just Boots | |
[email] => afrostyy@***.com | |
[hash] => 75ef8e4a8a8c7cbbb6698add2054c305 | |
[message] => I would like to view this post. | |
[activated] => inactive | |
) | |
) | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment