How to get a database field value from a WordPress table? [closed]

In the first two cases, there’s an array wrapping the object that you have to attend to first. e.g. this should work: $status = $user[0]->status; As a sidenote: In the last case, json_encode() doesn’t, as the name might suggest, turn data into an object with properties that you can access — it turns it into a … Read more

How to set variable to specific field when querying

Always sanitize input fields. Use $wpdb->get_var to check a single variable. You forgot to add the compare value to the WHERE clause. function username_auth() { global $wpdb; $username = sanitize_text_field( $_POST[‘custom_field_username’] ); $user_login_sql = $wpdb->get_var(“SELECT username FROM registration_info WHERE username=”$username” “); if( $username !== $user_login_sql ) { wc_add_notice((‘Incorrect username123’), ‘error’); } }

PHP Creating a formula from mysql db values and db stored math operator

ok, i managed to get it to work with this $amount1 = $invoice_amount; $operator = $invoice_operator; $amount2 = $invoice_multiplier; $rvalue = mcalc ($amount1,$operator,$amount2); function mcalc ($amount1,$operator,$amount2) { if($operator==”+”) $result=$amount1+$amount2; else if($operator==”-“) $result=$amount1-$amount2; else if($operator==”x”) $result=$amount1*$amount2; else if($operator==”/”) $result=$amount1/$amount2; return $result; } echo $rvalue;

SQL Query to get post_id from wp_posts and and meta_key(s) from wp_postmeta

You can do something like Query the wp_posts table Left join the source_name from wp_posmeta table Left join the coverage_url from wp_posmeta table Then select the data you want to pull from post, source_name and coverage_url result Something like this should do SELECT post.ID, post.post_title, sn.meta_value as source_name, cu.meta_value as coverage_url FROM wp_posts as post … Read more