Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Wordpress database - need sql that will add wp_usermeta first_name, last_name to query

Posted on 2014-04-17
2
Medium Priority
?
774 Views
Last Modified: 2014-04-25
I slapped together this sql which generates the users I need. I can't figure out how to add first_name and last_name to this from wp_usermeta. this is what I have so far:

Select * from wp_wpcw_user_courses,wp_wpcw_user_progress, wp_users where course_progress="100"and unit_id="457" and unit_completed_status="complete" and wp_wpcw_user_courses.user_id=wp_wpcw_user_progress.user_id and wp_wpcw_user_courses.user_id=wp_users.ID AND unit_completed_date > "2014-04-15 23:29:31"

Open in new window

0
Comment
Question by:phillystyle123
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 

Author Comment

by:phillystyle123
ID: 40008620
The logic for the whole thing would be something like this
Select * from wp_wpcw_user_courses,wp_wpcw_user_progress, wp_users where course_progress="100"and unit_id="457" and unit_completed_status="complete" and wp_wpcw_user_courses.user_id=wp_wpcw_user_progress.user_id and wp_wpcw_user_courses.user_id=wp_users.ID AND unit_completed_date > "2014-04-15 23:29:31"
    LEFT JOIN wp_usermeta ON wp_users.ID = wp_usermeta.user_id
        AND wp_usermeta.meta_key IN ('first_name', 'last_name')
    GROUP BY wp_users.ID

So, I'm trying to show:

ID, first_name, last_name, email
0
 
LVL 35

Accepted Solution

by:
Dan Craciun earned 2000 total points
ID: 40009027
You're almost there.

SELECT fields FROM wp_users
    LEFT JOIN wp_usermeta ON wp_users.ID = wp_usermeta.user_id
    WHERE wp_usermeta.meta_key IN ('first_name', 'last_name')
        AND (rest of your conditions here)
    GROUP BY wp_users.ID
0

Featured Post

Looking for a new Web Host?

Lunarpages' assortment of hosting products and solutions ensure a perfect fit for anyone looking to get their vision or products to market. Our award winning customer support and 30-day money back guarantee show the pride we take in being the industry's premier MSP.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question