• Hi,
    I would like to order posts within the category
    http://screencast.com/t/WoxG2syXFA2w

    and by default the wordpress order should be descending based on published date, but I want to order descending based on a custom field I use (event_end_date)
    Here is the code of the page and the order should be around the highlighted part:
    http://pastebin.com/v4mUv7zp

    I tried to use this code somewhere but I really don’t know how:
    query_posts($query_string . '&meta_key=event_end_date&orderby=meta_value&order=ASC');

    Anybody know how to do that?

    Thanks

Viewing 7 replies - 1 through 7 (of 7 total)
  • Thread Starter jumust

    (@jumust)

    Thanks for your suggestion! I’m not so good at php and when I tried to use the query_post I’m able to do very simple things…
    I really can’t understand the code I’m using in the home page (I pasted in pastebin in the previous post)

    Do you think this code is good?If so where should I paste it?
    query_posts($query_string . '&meta_key=event_end_date&orderby=meta_value&order=ASC');

    Actually I just copied this code from somewhere else…again I’m not good at all at php 🙁

    Thanks

    Thread Starter jumust

    (@jumust)

    One thing came up on my mind.

    The order from “query” function is for all posts in the page, right?
    What happens if I want to order only posts under one category?
    Actually I’m using a plugin to order/move categories up and down, does it mean I can’t order posts under single categories?

    Just to clarify with the plugin I can order categories like:

    Cat 3
    Cat 1
    Cat 5
    Cat 2
    Cat 4

    in the category 3 I have 4 posts:
    Cat 3
    Post 1
    Post 2
    Post 3
    Post 4

    I want to sort those posts by a custom field (event_end_date)

    Is it possible?

    Thanks

    global $query_string;
    query_posts($query_string . '&meta_key=event_end_date&orderby=meta_value&order=ASC');

    should do it. If the ordering isn’t correct try replacing ASC with DESC.

    Thread Starter jumust

    (@jumust)

    Thanks but it looks like it didn’t make any changes. I tried with ASC and DESC but posts are always in the same position.

    Here is the home page
    http://thisweekinmalibu.com/
    and here is the code with your new code implemented
    home page

    I have these posts whose end date are:
    Feb 14
    Feb 13
    Jan 22

    They look to be sorted ASC but if I change to DESC nothing happens so I just think it doesn’affect the site.

    I really don’t know what’s happening 🙁

    Thanks

    You need to ensure that your custom field end dates are in yyyy/mm/dd format to enable sorting by the field value.

    Thread Starter jumust

    (@jumust)

    Ah it sounds a little difficult as I don’t know but probably I need to change many things in the theme, and how?

    One thing came up to my mind: I’m using the same custom field to order post in category pages. It can maybe help you to understand what’s going on because the code is working there. If I use it in the home page it doesn’t, like your code… Here is the archive.php you can see the line 29-41

    Any ideas?

    Thanks

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Post order in category’ is closed to new replies.