Skip to content
Advertisement

How to filter record with specific condition?

I have a table called post which contains WordPress posts that have this structure:

each zoacres-property post have a meta stored inside the meta table:

I’m trying to filter the zoacres-property post by price, and I successfully did this using this query:

which returns:

this result is correct but, I would like to display all the property which have a price of 0 as first (as in the output), and after these, I need to display the property with a non 0 price using DESC, so the correct ouput the I want is:

As you can see the post with price 0 are the firsts displayed, and then I want get all the posts with the high price to lowest. Is possible achieve this?

I also created a FIDDLE HERE.

Advertisement

Answer

You can use conditional ordering as

DEMO

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement