php - Wordpress update_user_meta not working -
** solved ** had failed require wordpress in form processor. adding line @ top fixed (always simplest thing, right!?): require_once( explode( "wp-content" , __file__ )[0] . "wp-load.php" );
i've created custom front-end profile client's site, , i'm adding way other users favorite profile. (please don't suggest buddypress or plugin -- i've tried dozen, , none of them have of capabilities need. thanks.) :)
anyway.... here overview. hope it's clear. let's user 1 viewing profile of user 10.
- in database, user 1 has field called favorite_10 can set "yes" or "no" (or null)
- when clicks "favorite" button in user's profile, run simple script change value "yes" "no" or vice-versa
that's it. think it's pretty solution, form processing script breaking @ update_user_meta
line.
here go.
foreach($sitterlist $sitteritem) { $code = 'favorite_'.(esc_html($sitteritem->id)); $key = esc_html($sitteritem->id); $favorite[$key] = get_the_author_meta( $code, $currentuser); } $is_favorite=null; if ($favorite[$usertosearch]=='yes') { $is_favorite = true; } else { $is_favorite = false; } ?> <form method="post" action="updatefavorite.php"> <input type="hidden" value="<?php echo $usertosearch; ?>" name="usertosearch" id="usertosearch"> <input type="hidden" value="<?php echo $currentuser; ?>" name="currentuser" id="currentuser"> <input type="hidden" value="<?php echo $is_favorite; ?>" name="is_favorite" id="is_favorite"> <button type="submit" id="favoritebutton" name="favoritebutton"><span>favorite</span></button> </form>
and here updatefavorite.php
<?php if(isset($_post['favoritebutton'])) { $currentuserid = $_post['currentuser']; $currentprofileid = $_post['usertosearch']; $currentfavorite = $_post['is_favorite']; $code = 'favorite_'.$currentprofileid; if ($currentfavorite) { $currentfavorite = 'no'; } else { $currentfavorite = 'yes'; } update_user_meta($currentuserid,$code,$currentfavorite); } header('location: ' . $_server['http_referer']); ?>
after lot of testing , debugging, i've figured out it's breaking @ update_user_meta
... don't know why.
thank you!
** solved ** had failed require wordpress in form processor. adding line @ top fixed (always simplest thing, right!?): require_once( explode( "wp-content" , __file__ )[0] . "wp-load.php" );
Comments
Post a Comment