Hi. I want to be able to assign WP users to individual posts (in this case a custom content type called 'member organisation'). I use a custom $wpdb query to list all users and can associate them to the MO by creating a new postmeta entry with key 'mo-user' and value of the user's ID.
However, I can't delete them. Here's the code I'm using:
[Code moderated as per the Forum Rules. Please use the pastebin]
Any help appreciated. Thanks.
Jake
Here's the pastebin URL:
http://wordpress.pastebin.com/3tRCzjuQ
Thanks in advance.
After much digging I found this solution:
I got the id of the postmeta entry :
$assoc_users_sql = "SELECT m.meta_id, u.user_login
FROM $wpdb->postmeta m, $wpdb->users u
WHERE m.post_id = $post->ID
AND m.meta_key = 'mo-user'
AND m.meta_value = u.ID
ORDER BY u.user_login
";
For each listed user I used the id of the postmeta entry instead of the meta_value:
<input type="submit" name="deleteuser[<?php echo $a_user->meta_id; ?>]" class="deleteuser" value="Delete" />
and then delete_meta to remove the record:
if ( isset($_POST['deleteuser']) && $_POST['deleteuser'] ) {
foreach ( $_POST['deleteuser'] as $key => $value ) {
delete_meta($key );
}
}