Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8466891
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:28:43+00:00 2026-06-10T15:28:43+00:00

I have a custom WordPress table on a WordPress MultiSite called ihn_2_frm_item_metas used for

  • 0

I have a custom WordPress table on a WordPress MultiSite called “ihn_2_frm_item_metas” used for form entries.

Screenshot of database table is here: https://www.dropbox.com/s/ex54qxxohkexg5t/mysql.png

Right now, there are two entries. Each entry is given its own unique “item_id” (in this case, Bob Marley’s entry has the id of 10 and Molly Dolly’s entry has the id of 9). These entries also correspond to actual WordPress users (their username is their email address and their password(s) is “test”). The entry id is not the same number as their WordPress User Id.

I have logged in as “bob@marley.com” using the password “test.”

On the home page of the blog, I am wanting to display all of items in the “meta_value” column ONLY for the currently logged in user.

I want to do this in two steps:

  1. Find the email address of the currently logged in user (“bob@marley.com”).
  2. Find the “item_id” of that user’s form entry (10) that is on the same row of the matching email address.

Here is the code I have come up with:

    global $wpdb;
    global $current_user;
    get_currentuserinfo();
    $email = $current_user->user_email;

    $id = $wpdb->get_var( " SELECT item_id FROM ihn_2_frm_item_metas WHERE meta_value = $email " );
    $client_meta = $wpdb->get_results(" SELECT * FROM ihn_2_frm_item_metas WHERE item_id = $id " );

    echo '<p> $email is a ' . gettype($email) . '</p>';
    echo '<p> $id is a ' . gettype($id) . '</p>';
    echo '<p>The current logged in user is ' . $email . '.</p>';
    echo '<p>The current form entry id is ' . $id . '.</p>';
    echo "<ul>";

    foreach ($client_meta as $value) {
        echo '<li>' . $value->meta_value . '</li>';
    }

    echo "</ul>";

I have two gettype() statements simply in order to confirm that both of my varables, $email and $id are strings.

Here is the output of my code:

$email is a string.

$id is a NULL.

The current logged in user is bob@marley.com.

The current form entry id is .

Note that $id is NULL. What confuses me is that when I change the $id variable to this (replacing the variable $email with ‘bob@marley.com’):

$id = $wpdb->get_var( " SELECT item_id FROM ihn_2_frm_item_metas WHERE meta_value = 'bob@marley.com' " );

My output is exactly what I need:

$email is a string.

$id is a string.

The current logged in user is bob@marley.com.

The current form entry id is 10.

  • Bob
  • Marley
  • bob@marley.com
  • test
  • 8

Where have I gone wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T15:28:45+00:00Added an answer on June 10, 2026 at 3:28 pm

    You have omitted single quotes on $email:

    $id = $wpdb->get_var( " SELECT item_id FROM ihn_2_frm_item_metas WHERE meta_value = '$email' " );
    //---------------------------------------------------------------------------------^^^^^^^^
    

    This results in a syntax error in the query. I am not familiar with how WordPress handles those errors, but it is returning NULL on the unsuccessful query.

    If you don’t need to actually know the value of item_id other than to use it in the subsequent query, I suppose you could combine these into a single statement using an IN() subquery:

    $client_meta = $wpdb->get_results("
      SELECT * FROM ihn_2_frm_item_metas WHERE item_id IN (
        SELECT item_id FROM ihn_2_frm_item_metas WHERE meta_value = '$email'
      )
    ");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a custom table in my WordPress database named post_votes used for voting
I have a custom field in WordPress called thumb-url which contains the exact location
I have multisite Wordpress blog that have three custom fields that have text heading
I have a custom posttype in Wordpress 3. I would like to every post
I have 2 custom fields in my WordPress system when creating new posts. One
I have a custom search engine on a non-wordpress page. This search engine searches
I have a custom background image on one of my Wordpress login pages. After
I currently have a custom themed blog running on wordpress with Jetpack installed. I
I wanted to use the custom field for wordpress to have a different header
I am using the WordPress theme Studio8 and I have create some custom forms

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.