0

Hey guys so I am trying to access my database which is within wordpress to get some field values and I tried doing just straight up PDO style but it seems to not work so I went into wordpress codex and did their way to call things, but still no success!

CODE:

/***GET USERNAME***/
            global $current_user;
            get_currentuserinfo();
            $accusername = $current_user->user_login ;
            /******SEE IF FIRST TIME DISCOUNT CODE BEEN USED*******/
            $wpdb->query( 
                        $wpdb->prepare( 
                "
                        SELECT firsttime_discount
                        FROM $wpdb->users
                        WHERE user-login = %d

                ",
                    $accusername 
                                       )
                        );
                /******CHECK IT******/
                echo"working";
            $wpdb->query('query');
            echo"working";
            if ($checkFTDiscount->firsttimediscount != 1){
                    $validFTDiscount = 1;
            }
            else{
                $validFTDiscount = 0;
                echo"wori"; 
            }

So it's suppose to go in and see if the value for discount code is set to 1 in the wp_user area, and if not just set a value to 0.

Let me know if you have any other questions.

1 Answer 1

1

Before you can use $wpdb, you must declare global $wpdb;

    global $current_user, $wpdb;

Should do the trick.

Sign up to request clarification or add additional context in comments.

1 Comment

Further down the road, when you start doing PHP OOP, keep in mind that you in your constructor class you can add global $wpdb; $this->wpdb = $wpdb; to avoid re-declaring it every function within the object. This is something I didn't find out until today.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.