WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Sorting problem with 'query_posts' funcion. Sort by custom field not working! (7 posts)

  1. prionkor
    Member
    Posted 3 years ago #

    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.

  2. vtxyzzy
    Member
    Posted 3 years ago #

    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.

  3. prionkor
    Member
    Posted 3 years ago #

    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);
  4. vtxyzzy
    Member
    Posted 3 years ago #

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

  5. prionkor
    Member
    Posted 3 years ago #

    yes. I have seen the numbers there.

  6. vtxyzzy
    Member
    Posted 3 years ago #

    OK - missed the obvious. The parameter to query_posts is 'orderby', not 'order_by'!

  7. prionkor
    Member
    Posted 3 years ago #

    I AM THE GREATEST DUMMY OF THE WORLD

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

Topic Closed

This topic has been closed to new replies.

About this Topic