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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T04:58:50+00:00 2026-06-10T04:58:50+00:00

I am trying to get a data sorted from 2 tables posts and postmeta

  • 0

I am trying to get a data sorted from 2 tables posts and postmeta

Example wp_posts Table

ID      post_title          post_name
328   Test Event Five   test-event-five
326   Test Event Four   test-event-four
324   Test Event Three  test-event-three 
321   Test Event  Two   test-event-two 
320   Test Event One    test-event-one

Example wp_postmeta Table

id  post_id       meta_key                    meta_value
1    328      calendar_start-date            August 08, 2012
2    326      calendar_start-date            August 09, 2012
3    324      calendar_start-date            September 06, 2012
4    321      calendar_start-date            August 23, 2012  
5    320      calendar_start-date            September 17, 2012

In order to output the data ordered by the dates in the meta value, I am using the query

SELECT wp_posts.ID, 
       wp_posts.post_title, 
       wp_posts.post_name, 
       wp_postmeta.post_id,
       wp_postmeta.meta_value as event_date 
FROM wp_posts, wp_postmeta 
WHERE wp_posts.ID = wp_postmeta.post_id 
AND wp_postmeta.meta_key = 'calendar_start-date' 
AND wp_posts.post_status = 'publish' 
AND wp_posts.post_type = 'calendar' 
ORDER BY DATE_FORMAT( event_date, '%M %d, %Y' ) DESC 
LIMIT 0 , 30

But the result is not ordered by the dates, instead it is coming as

ID     post_title          post_name      post_id   event_date
328  Test Event Five    test-event-five     328     August 08, 2012
326  Test Event Four    test-event-four     326     August 09, 2012
324  Test Event Three   test-event-three    324     September 06, 2012
321  Test Event  Two    test-event-two      321     August 23, 2012
320  Test Event One     test-event-one      320     September 17, 2012

Where am I going wrong in the query and how can I display the records ordered properly by the event_date. The input format of the date is MM dd, yy through UI/Datepicker.

  • 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-10T04:58:52+00:00Added an answer on June 10, 2026 at 4:58 am

    DATE_FORMAT goes from DATETIME data types to strings. It doesn’t grumble when it fails, it just returns NULL. That’s why your query is working, even if the ORDER BY is not.

    You need to use STR_TO_DATE for what you’re trying to do.

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

Sidebar

Related Questions

I am trying to get data from my sql server data table to a
I'm trying to get sorted localized data from a core data model. My code:
So I'm trying to get data from my sql database and sort it by
I am trying to get data back from a PHP file assigned with GET
I am trying to get data from my interface, written in c, to another
I am trying to get the data for the Dow Jones Index from google.
I am using cakephp. I am trying get data from facebook using file_get_contents. I
I'm trying to get data from a namespaced xml file in a flex app.
I am trying to get data from different sever, and the sever name might
I am trying to get the top 'n' companies from a data frame.Here is

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.