Monthly Archives: January 2013

Sort on Presence of Custom Field, Field value, then Date

In order to sort on the presence of a Custom Field, you must use filters to modify the query created by query_posts().

We must join a new instance of the post_meta table, add fields for the sort_key (accounting for NULL) and the new meta_value, and add a new order by.

The code below is sample code and the display of the results must be altered to fit your theme and output needs.

Continue reading