• Resolved jakemc

    (@jakemc)


    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

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter jakemc

    (@jakemc)

    Here’s the pastebin URL:
    https://wordpress.pastebin.com/3tRCzjuQ

    Thanks in advance.

    Thread Starter jakemc

    (@jakemc)

    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.