简体   繁体   中英

How to match any of the two values from database?

I have some text in database1 and database2 tables that must match can_do($can, $user_id) function and if it doesn't match it will return false .

The problem is it checks both tables and returns false when database1 is set but database2 is not set. I need it to return true if database1 is set even if the database2 is not set and vice versa. How can I achieve that?

Here is the code:

   function can_do(  $can, $user_id ) {
        if ( $can ) {
            $test1 = get_user_meta( $user_id, 'database1', true );
            $test2 = get_user_meta( $user_id, 'database2', true );
            $function = get_functionvalue();

            if($test1 != $function OR $test2 != $function ) {
                $can = false;
            }
        }
        return $can;
    }

    add_filter( 'custom_wordpress_can_do', 'can_do', 10, 3 );

Just replace OR with AND , which will return false when both not matches.

if($test1 != $function && $test2 != $function )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM