If I want use the variable $post->user_id
in two functions like this it doesn't work. Why?
foreach ($usermeta as $post) {
echo $post->user_id;
echo $post->name;
echo $post->team;
}
function nicoupdate($post->user_id) {
update_usermeta( $post->user_id , 'ptotali', $_POST['ptolti'] );
}
I don't understand.
Still doesn't work:
$sql="SELECT `user_id`,
max(case when `meta_key` = 'name' then `meta_value` end) as name ,
max(case when `meta_key` = 'team' then `meta_value` end) as team ,
max(case when `meta_key` = 'ptotali' then `meta_value` end) as points ,
FROM wp_usermeta
GROUP BY `user_id`
ORDER BY points DESC";
global $wpdb;
$usermeta = $wpdb->get_results($sql) or die(mysql_error());
foreach ($usermeta as $post) {
echo $post->user_id;
echo $post->name;
echo $post->team;
}
function nicoupdate($user_id) {
update_usermeta( $user_id , 'ptotali', $_POST['ptolti'] );
}
What's wrong? If I put manually the user_id for example 3 it works.
Well - I've never seen that notation before. $usermeta as $post
is usually only used in a foreach statement. So first you need to drop the $usermeta as part of the function definition.
function nico($post)
....
Secondly, you are declaring another function with a variable, not with a name. Try this
function nicoupdate($user_id)
....
Then call it with:
noicoupdate($post->user_id);