Pho Enix
Pho Enix

Reputation: 43

wordpress - to find if a meta_value exists

I'm working on a wordpress site and I have custom field 'mobile' in usermeta table. When a user register, I need to check if mobile number exists.I'm using zm-ajax-login-register plugin which doesnot have a mobile field. I'm successfull in adding field and value to usermeta,but I cant validate. I tried like this,but metadata_exists is not the right code

if ( $user['mobile']!= ''){

        $your_custom_field= metadata_exists( 'user', $user->ID, $user['mobile'] );

        if($your_custom_field){
                $status =$this->_zm_alr_helpers->status('invalid_mobile');
        }


    }

Upvotes: 0

Views: 932

Answers (1)

Pho Enix
Pho Enix

Reputation: 43

Hooray.....Finally I got the answer...

$args = array(
            'meta_value'     => $user['mobile']
         ); 
        $user_mobile_exists=get_users( $args );
if ($user_mobile_exists) 
        {
            $status =$this->_zm_alr_helpers->status('invalid_mobile');
        }

Upvotes: 1

Related Questions