I am trying to use WordPress logged in user id which should search transaction_user_ID
in the table wp_m_subscription_transaction
.
The table has a column called transaction_user_ID
and another called transaction_paypal_ID
.
logic:if user id == transaction user id then get transaction paypal id
which should be passed to the url along with the user id email address and the execute the url to get the a code - this is my final output
How this can be achieved?
The code which I am developing is like this which is obviously incomplete & error for the getting and using the database query
<?php $user_id = get_current_user_id();
$query = "SELECT * FROM $wpdb->;wp_m_subscription_transaction
if ($user_id ==$query) {
<a href="http://primary.copyminder.com/cm_prodkey.php?DID=********&Password=*****&ProdCode=*******&NumRequired=1&TransNum=(GET THIS FROM DATABASE) &CustEmail=". $current_user->user_email .">Get ur Code</a>
}
else {
echo 'You are not logged in as user ';}?>
Try this query.
First, since you need the email address as well, get all the current user's details, not just the id, using
wp_get_current_user()
.Secondly, your query is wrong; you haven't closed the quotes, and have a stray semicolon. If I've read it right, you need something like:
If you're only getting a single value in a query, you can retrieve it with
$wpdb->get_var()
If the query doesn't return a row, it doesn't necessarily mean the user isn't logged in. You can check if a user is logged in using
is_user_logged_in()
.Something like this should work. I haven't tested, and you'll have to build up the URL yourself.
This code comes without warrant, because you've not provided database structure, field names, or many other factors.
However, treated as pseudo-code, this will get you going in the right direction.