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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:37:29+00:00 2026-05-25T10:37:29+00:00

Okay, so through WordPress, I’ve utimately ended up with a query string of the

  • 0

Okay, so through WordPress, I’ve utimately ended up with a query string of the following:

"SELECT * FROM wp_z4azbl_posts 
LEFT JOIN wp_z4azbl_postmeta ON(
    wp_z4azbl_posts.ID = wp_z4azbl_postmeta.post_id) 
LEFT JOIN wp_z4azbl_term_relationships ON(
    wp_z4azbl_posts.ID = wp_z4azbl_term_relationships.object_id) 
LEFT JOIN wp_z4azbl_term_taxonomy ON(
    wp_z4azbl_term_relationships.term_taxonomy_id = wp_z4azbl_term_taxonomy.term_taxonomy_id) 
LEFT JOIN wp_z4azbl_terms ON(
    wp_z4azbl_terms.term_id = wp_z4azbl_term_taxonomy.term_id) 
WHERE wp_z4azbl_term_taxonomy.taxonomy = 'opportunitytype' 
AND wp_z4azbl_posts.post_status = 'publish' 
AND wp_z4azbl_posts.post_type = 'opportunities' 
AND wp_z4azbl_postmeta.meta_key = 'date_timestamp' 
GROUP BY wp_z4azbl_posts.ID 
ORDER BY wp_z4azbl_postmeta.meta_value ASC"

Ultimately this works. It grabs my posts with a timestamp custom field and sorts it in ascending order. However, I need it to also append posts that don’t have a timestamp after all the posts that have a timestamp.

So right now, it showing something like this:

Event Title
January 1, 2011

Event Title 2
January 2, 2011

But I want it to append all posts without a timestamp:

Event Title
January 1, 2011

Event Title 2
January 2, 2011

Event Title Nostamp

Event Title Nostamp 2

How would I alter my query to get this to work?

EDIT

Sorry, I messed up on my original query. I actually need them to sort in ascending order with the non-timestamp posts still at the bottom.

  • 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-25T10:37:29+00:00Added an answer on May 25, 2026 at 10:37 am

    To include rows without a timestamp in the resultset, move meta_key = 'date_timestamp' from the where clause to on:

    LEFT JOIN 
            wp_z4azbl_postmeta 
    ON      wp_z4azbl_posts.ID = wp_z4azbl_postmeta.post_id
            and wp_z4azbl_postmeta.meta_key = 'date_timestamp'
    

    Since you are sorting descending, the null values will already appear on the bottom. null is treated as the lowest possible value for purposes of sorting.

    EDIT: To sort null differently, use a case:

    order by
            case
            when wp_z4azbl_postmeta.meta_value is null then 2
            else 1
            end
    ,       wp_z4azbl_postmeta.meta_value
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay, I've been working through a set of string replacments for bbcode style tags
Is it okay to get a read-only collection from an aggregate without going through
Okay, so I have this T-SQL statement: SELECT COUNT(DISTINCT RentalNo) as Count FROM RoomRental
Okay guys, I have read through all the other posts and question on jQuery
Okay, this question comes through a friend so it might be lost in translation...
Stepping through the debugger, the BBox object is okay at the entry of the
Okay i have already been through most of the ati and nvidia guides to
Okay so I'm trying to learn Java client/server stuff, and am going through the
Okay I've read through the plugin comments and the docs as well and I
Okay I have went through tons of examples on PARSing my JSON results, with

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.