• Resolved prionkor

    (@prionkor)


    Hi, I am working with a event listing system. There is a custom field in my post called starting_time which is unix timestamp. Now i want to short all posts by starting_time by this query_post command. I also dont want to show the already started events so i used a meta comparison :

    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    query_posts(array(
    'post_type' => 'event',
    'meta_key' => 'start_time',
    'meta_compare' =>'>=',
    'meta_value'=>time(),
    'order_by' => 'meta_value_num',
    'order' => 'ASC',
    'paged' => $paged
    ));

    But it not working. Here is the site http://citystir.com/events/. I am echoing the start_time in unix before the time remaining so you can see the value.

    reference: Order by parameter

    Another great post i have found here by sql but can’t get it working. Waiting for your reply soon.

Viewing 6 replies - 1 through 6 (of 6 total)
  • That looks like it should work provided the values for the meta_key = ‘start_time’ are actually stored as a number. Use phpMyAdmin or a similar tool to examine the postmeta table and see how the values are stored.

    Thread Starter prionkor

    (@prionkor)

    the start_time is actually unix timestamp which i made from the php funcion strtotime(); it should be number but for safety i also converted it to int before saving the meta field.

    $start_time = (int)strtotime($start_time);

    So did you look at in the database to be sure it is what you think?

    Thread Starter prionkor

    (@prionkor)

    yes. I have seen the numbers there.

    OK – missed the obvious. The parameter to query_posts is ‘orderby’, not ‘order_by’!

    Thread Starter prionkor

    (@prionkor)

    I AM THE GREATEST DUMMY OF THE WORLD

    I think i had checked everything without that! It worked!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Sorting problem with 'query_posts' funcion. Sort by custom field not working!’ is closed to new replies.