WordPress 1.5 plug-in: view future posts
At Starling Fitness we write many of the posts a few days in advance, which makes it much easier to ensure that we meet our goal of at least one post a day. WordPress lets you publish posts with future dates, and they stay invisible until their time comes. Unfortunately, you can’t view these future posts (except in the editor preview), and we like to see them as they will appear, complete with the site’s styles. So, I installed a Cheesy Hack(tm) a while ago to allow administrators to view future posts just like current ones.
I was working on a WordPress 1.5 version of the Cheesy Hack, and stumbled across a plug-in hook—so I realized I could write a proper plug-in instead. So here it is:
- Download futureposts.php.txt (WordPress 1.5 plug-in)
With this plug-in, an administrator can view future posts at their permalink, so the View links in the administration panel work just like regular posts. The posts only appear at their permalink page—they are omitted from the home page, archives pages, category pages, and RSS feeds. You can modify two variables to change these behaviors:
- $future_min_level—the minimum user level required to view future posts. The default is 10 (administrators). Set this to zero to allow everyone (even anonymous users) to view future posts.
- $future_single_only—if set to true (default), future posts are available from their unique permalink only. If set to false, future posts appear on the categories, archives, and the home page.
To install the plug-in: (WordPress 1.5 only) Download the file, rename it to futureposts.php, save it in your wp-content/plugins directory, then activate it from the administration Plugins page. That’s it!
This is my first attempt at a WordPress plug-in, so please let me know if you’ve found it useful, if it’s not behaving as you expected, or if you have a feature suggestion. Enjoy!
Update 7/20/2005: I’ve written an Enhanced Post Management plugin that adds additional features you might find useful for managing future posts.
Great idea! Those of us that heavily hack our templates can get unpredictable results, so the “correct preview” is helpful.
Wow, well done. I’ll have to try this out. This addresses a problem that many people are having in their attempts to do many different things. Personally, I am trying to use WordPress to power an events calendar on my site. There is a plugin called EventCalendar2 that has yet to be updated to 1.5 that works towards this.
Check this thread out: Blogging to the future
Thanks.
When I activate the plugin, I get a SQL error when viewing an individual post. Here’s the SQL:
SELECT DISTINCT * FROM wpposts LEFT JOIN wppost2cat ON (wpposts.ID = wppost2cat.postid) LEFT JOIN wpcategories ON (wppost2cat.categoryid = wpcategories.catID) WHERE 1=1 AND postname = ‘art-soul-lauren-winner-day-2’ AND (categorynicename = ‘writers-life’) AND 1) GROUP BY wpposts.ID ORDER BY postdate DESC
Which version of WP are you using? If it’s a recent beta they might have changed something in the SQL.
It’s the 1.5 version, not a beta. I think there was a minor bug fix to 1.5 that I haven’t upgraded to. I suppose I could try upgrading to see if that makes a difference.
I’ll check if that’s the difference. Do you know what version of MySQL you’re running?
I’m using MySQL version 3.23.58. I think the issue is in the variables and code that construct the SQL statement. Note that the SQL string the plugin is generating is creating an invalide SQL statement: “…AND (categorynicename = ‘writers-life’) AND 1) GROUP BY..” (not the “AND 1)” part). I suppose something in my environment or configuration is not letting your code construct the SQL statement properly. My blog I tested this on is crossoverfiction.com. I use ‘pretty URLs’ in case that makes a difference in how you’re grabbing the variables.
(oops, I meant to say ‘note the “AND 1)” part’…)
didn’t realize the correct term was Cheesy Hack™ – all this time I’ve been calling quick-n-dirty hacks
Is there a way to have future posts show on the calendar (hyperlink to the posting) just like past posts? I’m trying to implement an events calendar. Thanks for your hard work…the plugin is great!
Really annoying that wordpress doesn’t have this feature as standard. Thanks for this extra, very useful when layout matters!
Great plugin – I have installed it, and it’s working great. HOWEVER, even though I set $futuresingleonly=false, I’m not seeing “future archives” in the sidebar (i.e., even though I have June 2005 posts and May 2005 posts, only May 2005 shows up in the sidebar). Any ideas? I’m running a completely vanilla WP 1.5. Thanks again for the plugin!
This looks really cool. I have absolutely no clue on plugins and stuff. Would it be easy to modify this to be used to actually display future posts in a given date range and from a particular category?
I am not using this yet, but I bookmarked this post just in case I might something like this. I can see this become a standard WordPress feature.
How simple would it be to hack the plugin to allow the future posts to be viewed also on there cats page?
Im using this with EventCalender2 to allow for events to behiden from the front page, put viewed if they go to the actual postday but it would be good if they could also see it if they go to the cat aswell…
Hi, Great plugin! It works here with WP 1.5. But, as JJRedwolf, said, it would be great, if such an future event would be viewable in the calendar. For example, I can write an event for the 24. December 05, but when I jump to the december-page on the sidebar – calendar, I can nothing see on the 24the day in the calendar, like highlighted or hyperlinked. Would be great, thanks for listening! Markus
hi michael, thanks for a nice plugin.
i installed it, at first it was ok, but then i got this:
WordPress database error: [You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near ‘) GROUP BY wpposts.ID ORDER BY postdate DESC LIMIT 0, 10′ at ] SELECT DISTINCT * FROM wpposts WHERE 1=1 AND 1) GROUP BY wpposts.ID ORDER BY post_date DESC LIMIT 0, 10
any pointers?
Hi Michael, Thanks for this cool plugin. But unfortunately I get the same error like two others here in this thread:
WordPress database error: [You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near ‘) GROUP BY wpposts.ID ORDER BY postdate DESC LIMIT 0, 16′ at ] SELECT DISTINCT * FROM wpposts WHERE 1=1 AND 1) GROUP BY wpposts.ID ORDER BY post_date DESC LIMIT 0, 16
Do you have a hint or idea, what this could be? Thanks in advance Markus
An additon: Maybe the errors has something to to with the difference (languages??) between ” and ‘
When I change the line to $content = pregreplace(‘/AND postdate_gmt <= ‘.+’/’, “AND 1”, $content);
then I get “only” this error: No ending delimiter ‘/’ found in /home/sinus/public_html/blogxx/wp-content/plugins/futureposts.php on line 29
Does this help? Markus
Hi again, I changed the line to $content = pregreplace(“/AND postdate_gmt <= .+/”, ‘AND 1’, $content);
and it seems to work. Does this look for you OK, this line? Markus
I had the same problem, resolved by losing the single quotes:
$content = pregreplace(“/AND postdate_gmt <= .+/”, “AND 1”, $content);
However, fixed this by chance and not a seasoned PHP programmer, so I post it here as a report and not a solution…!
NB: there should obviously be an underscore in between preg and replace there.
I think, this plugin is very good. But one BIG problem I can see. I do not know, is it not possible or do I understand something wrong.
If I set the line $futuresingleonly—if set to true (default)
then I can see NO post from the future. I can see the day in the calendar is red and this is fine, but if I click on it, I can not see the post. How I could see this by a permalink, sorry, I understand not.
If I set the line to false, then everything is GREAT, BUT all the events in the future are in my page (index.php) at top, and this is not good in practice.
Say, you define some birthdays and events in the future (some monthes ahead) and a user posts an actual post (theme, thread), then first all future events appears and the danger is big, that the actual post will not be seen.
Did I undstood something wrong? How could I solve this? Thanks realy for hints. Markus
Hi I’m the author of the EventCalendar2 plugin that was mentioned above. I’ve just updated it to WP1.5, and I fixed the problem of how to show future posts like this:
function eventcalendarfilterwhere($where) { // Eliminate date restrictions if the query is day- or category- specific. global $wpquery; if($wpquery->isday || $wpquery->iscategory) return pregreplace("/AND +postdategmt *<= *'[-: 0-9]+' +/",'',$where); else return $where; } addfilter('postswhere','eventcalendarfilterwhere');
This filter removes the ‘postdategmt’ restriction from the WHERE clause, but only if the query is specific to a particular day or a category. That cheats a little bit – it would be better to only remove the restriction if the query was for the specific event category – but I opted for an easier user interface.
Plugin homepage: http://blog.firetree.net/2005/05/24/eventcalendar2/
Hi Alex, Thanks for your answer, I gave a longer answer on your own site. Markus
Not sure about this. A friend of mine hacked the view future posts in the earlier version of WordPress. I’d like to upgrade to the latest version, especially so I can use the 1.5 themes. Naturally when I tried updating, I broke his hack. I don’t know how he did this in the first place, and now he’s unreachable. Could you perhaps take a look at it and let me know if your plugin does the same thing? As you can see the upcoming events are a category of their own. http://brucewinick.com/Events/index.php?cat=2 I didn’t see any examples of the plugin on the fitness site, as today is 5/30 – so I didn’t get a chance to see it work… Ps. as you’ve probably guessed using plugins and stuff with wordpress is new for me too.
I too had the MySQL error mentioned several times here, specifically when trying to call the loop via queryposts. The vanilla method of calling the Loop worked fine, but this plug-in broke queryposts. I made the change mentioned here of removing the single quotes from
‘.+’
, and now all works fine.I’m making a site with WP for a small festival in my hometown. The website should therefore show all posts, past and future. Recent posts for the news section, and future posts for upcoming events in that week. Because everything is arranged by date I can let the news be a descending list and the events an ascending list.
Your plugin works and I can see all the future posts. But when I delete my history and cookies, the future posts are gone. I have to deactivate + active the plugin to see the posts again. So you see my little problem? If visitors delete their cookies, the site will be almost empty! But I don’t know how this can be? Also I found out the future posts will dissappear when I’m logged out???
Could you please help me with this?
I changed the $futureminlevel to ‘0’ instead of ‘1’, which seems to work. Hope it stays this way :)
I am using the plug in to show future posts, using an admin level of 0. I had to use the code Markus gave, but when I use that code I see my drafts as well as future posts.
I am confused to what “AND 1” means, and what it is replacing. Can anyone help?
[…] The Alex Harris Band will be playing at Royston Town football ground, this Sunday. The event is a beerfest, entry is £1, doors open at 2pm and we’re on between 2 and 3 pm. This will be our first gig, and I for one am rather excited! Come down, see us, and enjoy some ale. We won’t be hanging around for too long though, as we’re then off to play a private gig in Stevenage, we’re trying to get on some entertainment company’s lists. We’ll also be playing at the Portland Arms on Thursday June 2nd (doors open at 8pm, we’re supporting The Riptons and Tern, apparently, though I’m not sure this gig is confirmed yet), and at the Bombora Bar in Hitchin on June 9th. So we’re plenty busy! I bet if I was suitably motivated, I could make a page on this site that would display a calendar of my upcoming gigs, along with information about them. Hmmm, I’ll have to think about it, but I suspect I can do it by creating a post and setting the date to be that of the future gig, then using something like the view future posts plugin, or a bit of hackery… or, of course, I could find that someone’s done it already. As ever: how handeh. […]
Woo. this is really handy. It will allow me to view the posts that my team have added before they go live on monday morning with the release of the student paper.
Hello, is it possible for this plug-in to show the posts published for the future on the actual blog as well? I want to be able to have posts dated for the future actually on my site… and also shown in the Event Calendar plug-in.
http://www.otsumamimusic.com is the site. It is displaying information about music events which will happen in the future. I want to be able to get the events to show up on the future date in the Event Calendar actually.
If anyone has an idea on how to do this, let me know!
did anyone figure out how to restrict to a category?
It’s working if I made the change with erasing the simple quote here : ‘.+’ I’m using WordPress 1.5.2
Thanks !
I tried installing this, and also tried a number of the ammendments suggested but all to no avail.
With the straight dwonload I get nothing at all, no future posts showing, except in the Event Calendar category, but none on the main blog page which is what I needed.
When I changed the attribute to $futuresingleonly = false, then I get the MySQL errors listed above.
When I changed some of the entries as listed above, it actually removed entries from the Event Calendar category – they were still listed as scheduled on dashboard though.
I have tried all the options here and it seems that I just cannot get the future events on the front page.
I am using 1.5.2
Hi it’s me again. I’m glad with this plugin but I have a problem with the archives by year. Il I ask for an archive by year with your plugin active, I have the posts (it’s normal) but I also have the PAGES (that I don’t want).
Any idea ?
Many Thanks
Just to add that I have the same problem if I ask fot archives by months … I have the PAGES (I just want the Posts)
Thank’s.
I had no idea how to do a plugin before seeing this code, but I’ve been messing around with PHP for several months. Like others, I got errors.
Looking at the code, the key line seems to be:
$content = pregreplace(“/AND postdate_gmt <= ‘.+’/”, “”, $content);
This line is searching for a string in the command that WordPress sends to MySQL that tells it to only return things that have a date in the past. The problem seems to be that it replaces everything from the postdategmt part of the command to the command’s end.
What follows is a variation that only removes the part about the date. “.{22} means “the next 22 characters”, which is how long the actual date being passed is.
$content = pregreplace(“/AND postdate_gmt <=.{22}/”, “”, $content);
Hi.
I´m using wordpress 2.0 with event calender 3.0.2. I have installed your plugin and have made the following settings: // Minimum user level to view future posts (10=administrator) $futureminlevel=0; // true=only applies to single post pages (not the home page, category or date archives) // false=future posts are shown everywhere (if you’re a valid user) $futuresingleonly=false;
With this settings each page should be shown but they do not. Only in category views I can see future events. By clicking on a permalink the article cannot be shown. The same with commenting an article. :(
Here is a direct link to a future article. Try it by yourself please. Permanent example link
Do you have any ideas which will solve this problem?
Thx for your help.
Nice easy code. Thanks. I am using as part of a plug that I have created. It is an AJAX based Calendar, which can show posts, future posts, drafts, and private. The two together work well.
I have modified you code to put the options on an option page. I will be also makeing sure that it works with ver 2. Would would like to send it to you so you can post it. My I post it on my site as well.
Thanks
Michael C: Feel free to post your modified code on your site. I’ll take a look at it when I revise my plug-in.
It is now posted.
I have roughly the same parameters as Marcel, wp 2.0.4 and ec 3.0.4, $futureminlevel=0;
My goal is to allow future events to be viewed by anyone, with emphasis on anonymous viewers and viewers who are not logged in.
Something is missing. The permalinks for future posts ARE NOT visible, even to registered users whose access level is > X.
for wordpress 2.0.x a simple change to the regex worked for me. Using the regex as it is in the plugin was leaving and extra misplaced “)” in the sql query which breaks everything.
Change (line 29 in my copy) [code] $content = pregreplace(“/AND postdate_gmt <= ‘.+’/”, “AND 1”, $content); [/code]
to [code] $content = pregreplace(“/AND postdate_gmt <= ‘.+’)/”, “AND 1”, $content); [/code]
The replacement of the date string with “AND 1” (an always matched condition) seems a bit pointless to me as well. Why replace the date condition with and always matched condition when you can just remove the date condition? So, like so [code] $content = pregreplace(“/AND postdate_gmt <= ‘.+’)/”, “”, $content); [/code]
That also works for WP2.0.x, unless someone knows a good reason to have the “AND 1” in the SQL query?
sorry, the correct code should be
$content = pregreplace(“/AND postdate_gmt <= ‘.+’)/”, “”, $content);
note the escape “” before the newly added “)” in that expression
Thanks for this plug-in!
To those who have been getting the SQL error, the fix is to change the line
$content = pregreplace(“/AND postdate_gmt <= ‘.+’/”, “AND 1”, $content);
to
$content = pregreplace(“/AND postdate_gmt <= ‘.+?’/”, “AND 1”, $content);
Adding that question mark to the regular search expression prevents this plug-in from unintentionally removing large chunks of the SQL query conditionals generated by some versions of WordPress and/or other plug-ins.
I just can’t get this to work. I’ve tried all the different code changes offered here, but I get an error at line 29 every time. I’d like to make the values 0 and false, so that all future-dated posts show up on my home page and are viewable by everyone. But I just keep getting an error.
Would anyone be willing to look at my site and tell me what I need to do? I’d really love to use this plug-in, as it’s the only one I’ve found that does exactly what I want! Thanks
There seems to be some compatibility issues with WordPress 2.1 (Ella) – from what I can tell the command to list posts from today backwards has changed and no long gets modified by the plugin to include ALL dates (future and past).
Any one have a workaround, solution or update to the plugin? I’m stumped.
I am using WP 2.1.2 and event calendar 3.1.0. Has anyone updated this plugin? I would love to use it.
For those of you using WP 2.1.2 (maybe 2.1+) this solution fixed the plugin for the site I’m working on.
REPLACE this line: $content = preg_replace(…);
with this line: $content = pregreplace(“/poststatus = ‘publish’ OR poststatus = ‘private’/”, “poststatus = ‘publish’ OR poststatus = ‘private’ OR poststatus=’future'”, $content);
UPDATE:
My previous comment didn’t work for users who weren’t logged in, because of the post_status = ‘private’ parts. So, here’s the new replacement line that works for everyone.
$content = preg-replace(“/post-status = ‘publish’/”, “post-status = ‘publish’ OR post-status=’future'”, $content);
(remember these comments are filtered, so replace the -‘s with underscores).