Query two post types and order by two different date fields

I solved it with a bit of JS instead. Queried the two post types in a merged query and outputted each item with a ‘data-sort’ tag on each element. Then sorting the elements independently.

$archive_items.sort(function(a,b) {
    var an = a.getAttribute('data-sort'),
        bn = b.getAttribute('data-sort');                   
    if(an < bn) {
        return 1;
    }
    if(an > bn) {
        return -1;
    }
    return 0;
});
$archive_items.detach().appendTo($archive);

Perhaps not the most elegant and clean solution.

But thanks to Tom, Anton and rudtek for confirming this was not a standard and easy query.

Leave a Comment