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

  • SEARCH
  • Home
  • 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 5842593
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:02:17+00:00 2026-05-22T12:02:17+00:00

Currently I am working on a WordPress site, and I would like it to

  • 0

Currently I am working on a WordPress site, and I would like it to be possible to search for users on their first and last name on a part of my site.

WordPress makes use of a meta table to store any ‘extra’ data for a user. And the first and last name are some of those meta fields.

Now I am trying to create a query which gets me a result which returns me a user matching the first and last name, the only problem is that there is a meta row for last name and another one for first-name, they both do have a reference to the same user_id. Only I don’t know how I can create the query correctly.

When I have this query

SELECT U.id FROM wp_users AS U, wp_usermeta as US
WHERE U.id=US.user_id
AND (US.meta_key='first_name' AND US.meta_value='MyFirstName')

It does return the user I am looking for, however when I try this

SELECT U.id FROM wp_users AS U, wp_usermeta as US
WHERE U.id=US.user_id
AND (US.meta_key='first_name' AND US.meta_value='MyFirstName')
AND (US.meta_key='last_name' AND US.meta_value='Dijkstra')

I get no results at all, could someone help me?

In case someone is interested in the database structure, here ( http://cl.ly/6rGx ) is the users table and here ( http://cl.ly/6rts ) is the users_meta table.

Thanks in advance

  • 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-05-22T12:02:17+00:00Added an answer on May 22, 2026 at 12:02 pm

    You can’t join one row to two other rows of another table at the same time, so you need to join the other table twice, once for first name and once for last name. Like this:

    SELECT U.id 
    FROM wp_users AS U
    inner join wp_usermeta as UMF on U.id = UMF.user_id 
    inner join wp_usermeta as UML on U.id = UML.user_id 
    WHERE UMF.meta_key = 'first_name' 
        AND UMF.meta_value = 'MyFirstName'
        AND UML.meta_key = 'last_name' 
        AND UML.meta_value = 'Dijkstra'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently working on a wordpress 2.9.2 plugin (my first) that creates additional custom
I have a Wordpress site that I am currently working on and have set
I'm working on a community video site (Wordpress backbone) that will allow users to
I am working on a Wordpress site that users can login to and make
i'm currently working on a wordpress site that needs to have the option to
Am currently working on an application that requires users to submit posts and comments
I'm working on this site www.annapogossova.com for a friend. Currently the menu navigation is
I am working on a massive site for a client, but their current website
I'm currently working at a WordPress Plugin. It supports shortcode and creates DOM elements,
I am currently working on my Wordpress blog, which is hosted on a VPS.NET

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.