• Hi all,

    Background:
    I have a post category that is containing events. I add the event date to a custom field. I need the latest event to show on top but it is sorting on publishing date.

    I named the event date field: “event-date” and I enter date in the format of 2015-01-22 which makes it sort-able as string.

    This is the query I have been trying out, however it don’t seem to work.

    $args = array(
    	'meta_key'   => 'event-date',
    	'orderby'    => 'meta_value',
    	'order'      => $queryOrder,
    	'meta_query' => array(
    	array(
    		'cat'=> get_cat_id($categoryOne),
    		'posts_per_page'=> -1,
    		'showposts' => $listMax
    		),
    	),
    );
    
    $query = new WP_Query( $args );
    query_posts($query);

    Can anyone see what I am doing wrong? It still seems to sort on publishing date…

    Thanks in advance/Jesper Wilfing

    Ps. I have tried to set post publishing date to the event date and modified query to display unpublished posts. Had some problems with that, among other things I also needed to display past posts “if today” which was too tricky.

    Ps2. Maybe the easiest thing would be to find a plugin that could give me the data in JSON format. That would make it so much easier to handle by myself.

  • The topic ‘Sorting posts on meta value / custom field’ is closed to new replies.