Tag Archive for 'flutter'

Displaying Posts with a custom event date using Flutter

When I first heard about flutter at the Birmingham Wordcamp I was excited.  The project I was working on called for some custom fields, and I didn’t want the clients to worry if they typed a date in correctly.  Flutter can add a simple date selector when creating a post.  Since my knowledge of php programming is very limited and I am new to Flutter I searched online for a solution.

For my events section of the site, two things needed to be met:

  1. All posts in the events category to be ordered by the most recent event date
  2. All posts that are older than the current date to be excluded

There’s a great article on Doc4design.com (http://www.doc4design.com/articles/articles/flutter-date-field/) that explains a lot of the basic functions of Flutter along with inserting information from a custom Date field into wordpress. Also in this article is a link to php date display parameters.

This tutorial didn’t quite fit the clients needs so I searched the WordPress forums and found this http://wordpress.org/support/topic/288867?replies=5.  The post outlines how to use the query_posts  function to compare a custom date with today’s date, and ruling out any posts older than today.  The trick is to get the Flutter date formatting to match up with the current date in the query_posts code. Here is my final query_posts with the loop to display events. I went with a shorthand month and date display such as  Jan 10th, Oct 1st, etc.

Note: If you use this code make sure that your custom write field in flutter has the date format in the dropdown menu set to 4/20/08.

 <!-- Start the Loop. -->

    <?php
$today = date('Y-m-d');
query_posts('category_name=events&meta_key=eventdate&meta_compare=>=&meta_value='.$today.'&orderby=meta_value&order=ASC');
// special events query ... Doesn't show posts before current date
?>

  <?php while (have_posts()) : the_post(); ?>

 <!-- Display the Post's Content in a div box. -->
 <div class="entry">
<h4><a href="<?php the_permalink(); ?>"> <?php $thegottime = get('eventdate');
      $thetimestamp = strtotime($thegottime);
      echo date('M j', $thetimestamp);
      ?><span class="date-suffix"><?php echo date('S', $thetimestamp); ?></span> - <?php the_title(); ?></a></h4>
   <?php global $more;
$more = 0; ?>
   <?php the_content('<br><br>  Read More...'); ?>
 </div>

 <!-- REALLY stop The Loop. -->