Support » Fixing WordPress » Looking to Sort Custom Fields by Meta Data Values

Viewing 15 replies - 1 through 15 (of 15 total)
  • See the Orderby_Parameters and Custom Field Parameters of the template tag, query_posts().

    Got it to sort by one meta_key value using this syntax:

    But I really need it to sort by month, day and year. Doesn’t seem to be possible using simple query_posts().

    If you don’t order by meta_value it will be sorted, by default, by date.

    Meaning, just use meta_key= and meta_value= to filter, and don’t use the orderby clause.

    That’s the thing, if I just use something like:

    Then I’m back to where I started as I don’t want to order by post date (which is what I think you mean by “date”), I want to order by the date I have specified in the custom fields, which does not correspond to the order in which I am posting events.

    Jeesh was I being dense or what?

    Can’t you create one custom field with the date? Make it a whole heck of a lot easier 😉

    Yeah, I guess I could do that. I was using custom drop down fields to avoid keying in invalid date format, but I can switch to a textbox, it will probably make my life easier (as long it sorts).

    Well Hiroaki Miyashita does a good job with the Custom Field Template plugin, so I wonder if there’s a way to ‘validate’ the date field. I put the cutom-field-template tag on this thead — maybe Hiroaki Miyashita likely see this and have a suggestion 😉

    OK, thanks. (Your anchor tag in the above post appears to be a bit messed up.)

    So I got went ahead and added a date field, but unfortunately and not so surprisingly it didn’t like any dates that started with numbers 10-12 and refused to pull them as part of the query. The weird thing is, is that when I went back to change the metadata to a month that starts with 1-9, it refused to pull that post again no matter what I did.

    Finally figured it out. The query_posts was only bringing back 15 records (as is set in my options), it had nothing to do with the date of the show in “start date” custom field. Just so happened that the ones at the end started with larger numbers. You can check it out in all its glory over here.


    Hey moderator,
    If I wanted to post my calendar code somewhere on, what would be the best place? It’s not quite a plugin, it’s more of a hack or just creative use of an already existing plugin.

    I posted the code for the calendar with a little explanation on how it works over here.

    Could anyone explain how I can sort by meta_key=surname and then alphabetically by meta value asc ?


    Ok, i got stuck in and sorted it with a Custom Select Query in category.php

Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘Looking to Sort Custom Fields by Meta Data Values’ is closed to new replies.