Support » Fixing WordPress » delete_post_meta problem for multiple meta entries using the same metakey

Viewing 2 replies - 1 through 2 (of 2 total)
  • 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 );
    		}
    	}

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘delete_post_meta problem for multiple meta entries using the same metakey’ is closed to new replies.