In my WordPress blog I have events I want to order and filter by custom fields. The order should be done by the custom field "event_date_end" which means that every event that is still running should be displayed.

To order the events I use a second custom field "event_date_start". So an event, that start on the 10th and ends on the 20th it should be displayed until the 20th but should be order next to all other events starting at the 10th.

I use Thematic as a parent theme and so I use the query_posts() function adding both rules as parameters. This is how I use it in the index loop:

    function my_index_loop($content) {
        global $query_string;
        query_posts($query_string
        // filter by event_date_end
        ."&meta_key=event_date_end&meta_compare=>=&meta_value=".date('Y-m-d')
        // order by event_date_start
        ."&meta_key=event_date_start&orderby=meta_value&order=ASC"); 
    }
    add_filter('thematic_indexloop', 'my_index_loop');

Now the posts are correctly ordered, but also the filter will be done on the "event_date_start" value. So an event, that has been started yesterday and still going on, will not be displayed.

If I switch the order of the "filter" and "order" parts, I will see all events, but an event starting at the 10th and ending at the 20th will be placed to all event on the 20th.

I know I can create queries in SQL myself, but will they work with Thematic? And how do I have to write statements for archive, category, tag listing?