[EventCalendar] ordering events category: one step closer -SIMPLE question

Ray Petrie ray at heritagepark.com
Thu Feb 15 23:47:48 UTC 2007


Nadia, I have been working on the same thing for over a month off and on. It
was a good way to get familiar with php, mysql and phpmyadmin. I figured out
how to do a query with left joins using the separate table with the start
date and the category table.  It worked except that you had to put error
traps in for the end of listings and pagination. Here is part of the code if
you want to review it.  This is not the modular way that coding is done on
wordpress and ec3 and I think there may be a way to do it with the existing
code in ec3.
*******************************************************
 if ( !(in_category('1')) && (!$wp_query->is_date) ) {
// sort by start date and limit display to records for today and the future
//$posts = query_posts($query_string . '&orderby=title&order=asc'); this
works, but not what I want
// query_posts('cat=7&orderby=title'); this does not consider start date

$posts = $wpdb->get_results("select * from (wp_posts left join
wp_ec3_schedule on wp_posts.ID=wp_ec3_schedule.post_id)  left join
wp_post2cat on wp_ec3_schedule.post_id = wp_post2cat.post_id WHERE
wp_ec3_schedule.start >= NOW() AND wp_post2cat.category_id = $cat ORDER BY
start",OBJECT);

// run the query again just to get a record count
$query = "SELECT COUNT(*) FROM (wp_posts left join wp_ec3_schedule on
wp_posts.ID=wp_ec3_schedule.post_id)  left join wp_post2cat on
wp_ec3_schedule.post_id = wp_post2cat.post_id WHERE wp_ec3_schedule.start >=
NOW() AND wp_post2cat.category_id = $cat ORDER BY start";
$post_count = $wpdb->get_var($query);
}
*******************************************************
I fine tuned my query by running it with phpmyadmin until I got the results
I was looking for. Then I plugged it into the wordpress archive.php file
before the have_posts()
Use the post_count variable to know how many entries there are and a counter
in The Loop to trap for time to break from the loop.  Figuring out how to do
the pagination was so perplexing that I gave up.

It looks like you can use the info from
http://wpcal.firetree.net/advanced-queries/  because is says it will be
sorted by the start date.  But it does not seem to be when I do it.
?ec3_days=N

This works to provide the rss feed in date order for next 7 days
http://blog.address/wp-rss.php?ec3_days=7

You could use the function ec3_the_schedule() and perhaps modify it to show
more data.

Another way, not pretty, is to write a php routine to update the database
putting the start date in as the post date.  I didn't do that because I
still think it can be done with the code already present.

Something to think about?

Ray






More information about the EventCalendar mailing list