• Resolved theshine

    (@theshine)


    I wanted to keep track of each concert I post about, so I created some custom fields for my blog (using the Custom Field Template Plugin) that show up at the bottom each time I create a post. Those fields are: band name, day, month, year, venue, etc. Using those custom fields I created a new page (with a new calendar.php page template) called “Upcoming Show Calendar” that lives over here. The page works fine except the events are not ordered chronologically, I would like to sort them by the custom field values of “day”, “month” and “year”. Any ideas how I might do that? Right now the page meta data is being retrieved by this query_posts: query_posts('meta_key=band%20name&order=DESC');

    I want to do something like this (pseudocode):

    query_posts('meta_key=band%20name&order=meta_value:year&meta_value:month&meta_value:day');

    I know that syntax is wrong, but is there any way to do it? Do I need to use a wp_query rather than query_posts?

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

    Thread Starter theshine

    (@theshine)

    Got it to sort by one meta_key value using this syntax:
    query_posts('meta_key=band%20name&orderby=meta_value&meta_key=month&order=ASC');

    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.

    Thread Starter theshine

    (@theshine)

    That’s the thing, if I just use something like:
    query_posts('meta_key=band%20name');

    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 ??

    Thread Starter theshine

    (@theshine)

    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 ??

    Thread Starter theshine

    (@theshine)

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

    Thread Starter theshine

    (@theshine)

    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.

    Thread Starter theshine

    (@theshine)

    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.

    Nice.

    Thread Starter theshine

    (@theshine)

    Hey moderator,
    If I wanted to post my calendar code somewhere on www.remarpro.com, 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.

    Thread Starter theshine

    (@theshine)

    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 ?

    thanks,

    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.