0

hello I save the values as here: Add value to usermeta without removing previous values?

$email_suscriptor = $_POST['cancelsus'];

$dismissed = array_filter( explode( ',', (string) get_user_meta( $vendor_id, 'emails_suscriptores13', true ) ) );

if ( ! in_array( $email_suscriptor, $dismissed ) ) {
    $dismissed[] = $emailsus;
 $dismissed =  implode(",", $dismissed);
   update_user_meta( $vendor_id, 'emails_suscriptores13', $dismissed );
}

Result:

 $list_emails= get_user_meta( $vendor_id, 'emails_suscriptores13', true );

echo $list_emails;

so it looks:

[email protected],[email protected],[email protected]

Users send their emails from a subscription form and I can save them with this code but I can't delete their emails (values within the user meta)

the problem is that I can't delete them

in my role I save emails from subscribing users so I need to be able to delete an email when someone wants to do it

try delete_user_meta, using the same code but it doesn't work

Don't work:

$cancelsus = $_GET['cancelsus'];

if (isset($cancelsus)) {

$dismissed = array_filter( explode( ',', (string) get_user_meta( $vendor_id, 'emails_suscriptores13', true ) ) );

if ( ! in_array( $cancelsus, $dismissed ) ) {
 $dismissed[] = $cancelsus;
 $dismissed =  implode(",", $dismissed);

   delete_user_meta( $vendor_id, 'emails_suscriptores13', $dismissed );
}
}

4
  • Can you show the code that you tried?
    – Howard E
    Nov 20, 2021 at 23:06
  • yes, i tried this: $dismissed [] = $emailsus; $dismissed = implode (",", $dismissed); delete_user_meta ($vendor_id, 'emails_subscribers13', $dismissed); just change update to delete
    – mario
    Nov 20, 2021 at 23:21
  • So you're trying to delete a value from an array of user_meta? The value is an array, and you want to remove one value from the array?
    – Howard E
    Nov 21, 2021 at 0:26
  • What I am trying to remove is an email (value) inside an array of user_meta. As I try to explain, I have a simple form where users send their email and so I save those emails within the user_meta array to subscribe. But then I have to remove them when they want to unsubscribe and I don't understand how to remove a value. I will update my question for a better understanding
    – mario
    Nov 21, 2021 at 0:42

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.