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 8854233
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:50:14+00:00 2026-06-14T13:50:14+00:00

I have a custom query to pull users with their user_meta for a statistics

  • 0

I have a custom query to pull users with their user_meta for a statistics plugin I wrote. I am able to select (WHERE) based on a date range, as well as ORDER BY any of the meta fields, however, I cannot do both at the same time. I am losing my mind!! Here is my query (with default variables for reference underneath) …

$getUserData = $wpdb->get_results("SELECT
ID, user_email, user_registered,
first_name.meta_value as first_name,
last_name.meta_value as last_name,
telephone.meta_value as telephone,
country.meta_value as country,
company.meta_value as company,
address.meta_value as address,
city.meta_value as city,
professional_title.meta_value as professional_title,
state.meta_value as state,
areas_of_interest.meta_value as areas_of_interest
FROM wp_users
LEFT JOIN wp_usermeta AS first_name ON first_name.user_id=ID
    AND first_name.meta_key='first_name'
LEFT JOIN wp_usermeta AS last_name ON last_name.user_id=ID
    AND last_name.meta_key='last_name'
LEFT JOIN wp_usermeta AS telephone ON telephone.user_id=ID
    AND telephone.meta_key='telephone'
LEFT JOIN wp_usermeta AS country ON country.user_id=ID
    AND country.meta_key='country'
LEFT JOIN wp_usermeta AS company ON company.user_id=ID
    AND company.meta_key='company'
LEFT JOIN wp_usermeta AS address ON address.user_id=ID
    AND address.meta_key='address'
LEFT JOIN wp_usermeta AS city ON city.user_id=ID
    AND city.meta_key='city'
LEFT JOIN wp_usermeta AS professional_title ON professional_title.user_id=ID
    AND professional_title.meta_key='professional_title'
LEFT JOIN wp_usermeta AS state ON state.user_id=ID
    AND state.meta_key='state'
LEFT JOIN wp_usermeta AS areas_of_interest ON areas_of_interest.user_id=ID
    AND areas_of_interest.meta_key='areas_of_interest'
" . $where . " 
ORDER BY " . $orderBy . " " . $sortOrder . " LIMIT 0, " . $page_limit);

 $where = "WHERE (user_registered >= '" . $_REQUEST['from'] . " 00:00:00' and  user_registered <= '" . $_REQUEST['to'] . " 00:00:00') ";

$orderBy = "user_registered";

$sortOrder = "ASC";
  • 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-14T13:50:15+00:00Added an answer on June 14, 2026 at 1:50 pm

    hint – mysql_error() telling us that if you place your variables correct you still forgeting to set there $page_limit

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following custom query: @initial_matches = Listing.find_by_sql([SELECT * FROM listings WHERE industry
I have a custom SQL query that I run with this line: @avg_score =
Lets say that we have a query like this one: SELECT *, (CUSTOM_EXPRESSION) as
I have problems creating a custom query. This is what entities: @Entity public class
I need a custom query pagination in CakePHP 1.2. I have a reviews model
Is there a way with ActiveRecord to execute a custom SQL query and have
I have custom control and I have interface this control exposes to it's users.
I have a custom query in WordPress that is pulling a time assigned to
Is there a way to have a custom order by query in sqlite? For
I have a custom Keyboard Query Shortcut in SSMS (2008) with the following t-sql...

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.