In which I explain a bit of MySQL

WordPress Wednesday: Displaying Older Posts

WordPressI’m suffering from a little bout of writer’s block these days. When you combine that with the fact that I haven’t been cruising the ‘net finding new and funny things, it makes for a dearth of new content on this site. I was thinking that it would be cool to display a single post from the archives at the top of the home page when there’s nothing new to see. Something like, “Hey! Sorry I haven’t posted anything new in x days, but check out this from y years ago …” I got as far as writing the SQL for it, but then I stopped working on it. I think it’s a good idea, though. Maybe someone will decide to write a plugin to do this. (Or, more likely, someone already has and I am just too lazy to find it.)


In case anyone is interested, here is the SQL to find a post written on “this day prior to today”:

select * from wp_posts where date_format(post_date, '%m/%d') = date_format(now(), '%m/%d') and date_format(post_date, '%Y') < date_format(now(), '%Y') and post_status = 'publish' and post_type = 'post' order by comment_count desc, id desc limit 1

The query sorts by the post with the most comments on the assumption that that is probably the most interesting post if there were multiple posts on that day.

Post the first comment:

I'll never share your email address and it won't be published.

What Is This?

davidgagne.net is the personal weblog of me, David Vincent Gagne. I've been publishing here since 1999, which makes this one of the oldest continuously-updated websites on the Internet.

bartender.live

A few years ago I was trying to determine what cocktails I could make with the alcohol I had at home. I searched the App Store but couldn't find an app that would let me do that, so I built one.

Hemingway

You can read dozens of essays and articles and find hundreds of links to other sites with stories and information about Ernest Hemingway in The Hemingway Collection.