Forums

Can't seem to sort by custom field value AND then by date? (4 posts)

  1. codeamatuer
    Member
    Posted 8 months ago #

    Okay, so I am using a custom field called 'reviews'. Posts using this field will contain a number from 1 to 5. What I'm trying to do is order posts from the highest number down to the lowest number, which I can achieve using the following code:

    query_posts('meta_key=reviews&meta_compare=<=&meta_value=5&orderby=meta_value&order=DESC');

    Now this works great, but the problem is that I also want the ordered post to be chronological too, so if I have two posts with the custom field value 5 I want the most recent post to be higher in a list than the older one.

    Is this even possible? Or is it something that can only be achieved with a plug in?

    Many thanks.

  2. beepmebeep
    Member
    Posted 8 months ago #

    Did you figure this one out? Let me know because I've been tearing my hair out for a couple of days on this one too.

  3. nsathees
    Member
    Posted 8 months ago #

    I don't have such setup to test it but just wondering what will happen if you append orderby again?

    In any case I will solve this by getting the ID and publish date and inserting them to an array then sort the array by date and then publish them.

  4. codeamatuer
    Member
    Posted 8 months ago #

    Thank you for your feedback nsathees. That sounds a pretty good idea. I'm a bit of a tinkerer when it comes to php - not really that competent but will attempt to try this out - arrays definitely seem the way to go.

    I'll let you know how i get on and if this is successful as it will help others who have this problem.

    Cheers.

Reply

You must log in to post.

About this Topic