mysql - PHP write a conditional statement based on whether an argument is in a database or not -


i developing wordpress plugin. there variable send database once payment has been made, ispayment , set 1. if payment has not been made, variable not sent database...so there instance where, particular post id, variable "ispayment" not exist.

i'm trying write conditional statement based on whether variable present or not.

what i'm trying is, if wedding_form_final_submit = 1 , there no ispayment variable - $status = foo. else, if wedding_form_final_submit = 1 , ispayment = 1, $status = bar.

here have far:

if(get_post_meta($post_id,'wedding_form_final_submit', 1) && get_post_meta($post_id, 'ispayment',false)) {             $status = 'form complete';         } elseif(get_post_meta($post_id,'wedding_form_final_submit', 1) && get_post_meta($post_id, 'ispayment',true)) {             $status = 'deposit paid';         } else {             $status = '';         } 

currently, returns "form complete" it's entry should return deposit paid, entry should form complete blank.

i believe issue first statement, variable ispayment doesn't exist. how ammend though?

this code below do, if post meta you're retrieving doesn't exist, variable return empty

// post meta value 'ispayment' $paid = get_post_meta( $post_id, 'ispayment', true );  //check post meta exists , value 1 if ( isset($paid) && $paid === '1' ) {      $status = 'form complete'; //if post meta doesn't exist or value not 1. } else {     $status = 'deposit paid'; }  //or shorter  $paid = get_post_meta( $post_id, 'ispayment', true );  $status = ( isset($paid) && $paid === '1' ) ? 'form complete' : 'deposit paid'; 

just add other code in there


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -