• Hi,
    I’m new to PHP and I was wondering if I could get help on how to check my WordPress database if a value in a custom field I created exists already. For example, a user stores the value “45fg” in his profile in the custom field “coupon” and another user wants to save the same value, the system should not allow him because “45fg” is being used by a different user. The custom field has a meta_key “coupon_number” that I can see in my database under the table wp_usermeta. To make things easier, is there any plugin that can do this?
    Thanks for the help!

Viewing 1 replies (of 1 total)
  • Hello jamestrada,

    We can use the below code for checking the meta_value exit or not:

    From here, you can then iterate through the list of users to find what you need:
    
    if(!get_users_by_meta_data( 'my_key', 'my_value')){
    //add you meta here
    }

    Thanks

Viewing 1 replies (of 1 total)

The topic ‘Check existing value exists in database’ is closed to new replies.