• I have made a site for a small festival, and because that festival is in the future, I couldn’t use the postdate as a means of sorting the content by eventdate. So now I have a site in which people can view the pages (events) by date/sort of event/location. But all these three options I had to create by using custom fields. And the customfield ‘date’ is formulated as ‘wednesday october 18 th’.
    Has someone an idea of how I could get some kind of order in the display of the pages (preferably by date), because now all the events are shown correctly by there customfield, but not by date. Could I for instance add another customfield with the actual dateformat (11-10-2004) and sort that customfield? Is it possible at all to sort customfields?

Viewing 7 replies - 1 through 7 (of 7 total)
  • Moxie, or anyone else, have you found a solution yet?

    I’m looking to do the same thing, sort posts based on a date in the custom field.

    This plugin would be every useful…
    If anyone have any ideas on how to approach this problem, please reply.

    I too have a similar problem. On the website I run for a band, I list all their upcoming gigs using a seperate loop from the main loop, on the main page. The date for the upcoming gigs are custom fields, and I’d like to sort these posts in descending alphabetical order by their custom field values.

    Here’s the code for that partiular loop:
    <?php $my_query = new WP_Query('category_name=Gigs&showposts=10'); ?>

    <?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
    <p><b><?php echo get_post_meta($post->ID, date, true); ?></b> - <a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></p>
    <?php endwhile; ?>

    I’m sure it’s just something simple that needs to be added to the WP_Query, but I don’t know what. Any help would be much appreciated.

    Thread Starter Jack

    (@moxie)

    I’m working on a new version of this site (I posted this topic one year ago ?? ), and I’m trying out a different approach which could perhaps help other people as well. But I must warn you, I’m not a php wizard, far from that :(.

    I’ve done a few things:
    Installed the future-posts plugin and set the minimum admin-level within that file (edit file itself) to ‘0’ so that I can make posts with a future date that will all appear on the site. All those dates are within one week in october later this year. This way I don’t need to use the customfields anymore for the dates.
    Besides that I’m also using a ‘news’ category, which should show the dates as they are actually are.
    The newspage should order with the newest on top, the events date should order from october 23 to october 28.

    So I put this on top of my indexpage:

    if ($cat==3){
    $orderby=”date”;
    $order=’DESC’;
    } else {
    $orderby=”date”;
    $order=’ASC’;
    }

    The ‘else’- categories are all posts with events with future dates. This all works, although I can’t show you the link for now, because the eventspage’s and menu are disabled until the events are certain to take place.

    Well, I decided to take a raw DIY approach and used a few of my own variables, queries, and loops to accomplish my particular goal; using specific knowledge of how and where certain data is stored in the WP database.

    <div id="gig_schedule">
    <h4>Gig Schedule</h4>

    <?php $gig_query = mysql_query("SELECT post_id FROM wp_postmeta ORDER BY meta_value ASC"); ?>

    <ul>
    <?php
    while ($query1 = mysql_fetch_array($gig_query)) {

    $title = mysql_result(mysql_query("SELECT post_title FROM wp_posts WHERE ID='$query1[post_id]'"), 0);
    $url = mysql_result(mysql_query("SELECT guid FROM wp_posts WHERE ID='$query1[post_id]'"), 0);

    echo "<li><a href="$url">$title</a></li>n";

    }
    ?>
    </ul>
    </div>

    As you can see, it’s not integrated into WP at all, so it cannot be used as a plugin in its current state (also because it obviously caters only to my specific needs, though I imagine it could easily be altered to take other needs and situations into account). Also, because it works completely separately from WP, this happened to solve my other problem with using blog pages with multiple loops.

    If anyone has any suggestions as to how this could be improved or integrated into WP better, please do reply.

    For what it’s worth, Event Calendar 3 can do this easily, without having to set the date by a custom field, but rather simply editing the timestamp.

    I’ve got the same issue, and for me, Event Calendar is not just yet it. I’ve got multiple event categories, each post with some custom fields, and i’d like to be able to display a little list in a sidebar, with the 5 upcomming events of one particular event-categorie.

    So far, i’ve managed to do this in pure php, by creating an array and sorting it in the way i need, but any wordpress template tag-code after that wont work anymore.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Sorting by custom field content’ is closed to new replies.