For an external development I needed to be able to display future posts but not all future posts. I started with the future posts plugin of Michael Moncur but it doesn’t fit to what I really needed.

The posts to be displayed should have been maximum 20 days in the future…

So the plugin is now able to display the future posts of ‘x’ days (defined via an simple administration screen).


To have that I wrote “nearfutureposts plugin.

To install the plugin :

  • copy the nearfutureposts.phps file in the wp-content/plugin directory (don’t forget to rename it as ‘nearfutureposts.php’).
  • Activate the plugin.
  • define the number of days in future to display via the menu “Option/NearFuture” (default value sets to 30 days)

10 commentaires

  1. this is so close to what i’m looking for. the handy events plug-in was a just a bit too complicated, since i don’t need one of those little ‘calendar views’. are you continuing any work on this?

    i just wonder if you can point me in the right direction to customize your plugin.

    it looks like i need to restrict to work only in certain categories, and then, make the old posts disappear… I first started with: “is there a way to make it so ‘old’ posts don’t appear?”

    now, i can’t understand how the plugin works, but i have this funny feeling that making ‘old’ posts not appear would change the behaviour across the whole site… so one would need to restrict it to only specified categories.

    i was also wondering how can i change the direction, ASC or DSC. but then, i might just make custom category templates, and then have them appear in reverse order!

  2. Well, I suspended my developments for a while….(see shani.idahocline.info for further information)…

    But you can try to specify a “starting date” or a number of days per category….

    Do you see what I mean ?

    If not, just let me know….

  3. very sorry to bother you again. i tried to figure out how to do this, and i’m failing.

    i want to be able restrict the nearfutureposts to only work in 2 categories. so, i tried wrapping the function in an if statement…

    … “if ( in_category(‘events’) || in_category(‘festivals’)) { “…

    but this does not work.

    do you have any advice?

    i also thought about making a custom category template, but once activated, nearfuture does it on every category of course.

    any advice you can offer would be great.

  4. Have you tried to modify the sql statement in the nearfutureposts plugin ?
    In wp_near_future_posts() something like….

    AND ".$wpdb->post2cat."category_id in (1,2,3)

    where you will replace the (1,2,3) with your category id’s….

    Should work. Not tested but….

    Good luck

  5. watch out when you copy the code, there’s a space behind the last ?> witch was giving me errors
    remove the space and everything should work fine!

  6. i was looking for “AND “.$wpdb->post2cat.”category_id in (1,2,3)” in the nearfutureposts plugin… and didn’t see it… (sorry i don’t know SQL at all!)

    i’ve tried a bunch of different things… but finally i can’t figure out where to put the code you paste above. the best i got were SQL errors (when it didn’t break my site)…

    here’s one place i pasted it:

    $content = preg_replace(“/AND post_date_gmt post2cat.”category_id in (1, 2, 23)”, $content);

    which gives this error:

    SELECT DISTINCT * FROM wp_posts WHERE 1=1AND category_id in (1, 2, 23) GROUP BY wp_posts.ID ORDER BY post_date DESC LIMIT 0, 10

    also:

    $content = preg_replace(“/AND post_date_gmt post2cat.”category_id in (1,2,3)”, “AND “.$wpdb->post2cat.”category_id in (1, 2, 23)”, $content);

    which gives this error:

    SELECT DISTINCT * FROM wp_posts LEFT JOIN wp_post2cat ON (wp_posts.ID = wp_post2cat.post_id) LEFT JOIN wp_categories ON (wp_post2cat.category_id = wp_categories.cat_ID) WHERE 1=1AND category_id in (1, 2, 23) GROUP BY wp_posts.ID ORDER BY post_date DESC LIMIT 0, 10

    sorry to be annoying, and i respect your busy-ness..

    but can you advise me on what this line should look like?

    thank you!

  7. oh dear. my third comment. i’ll stop now. i just wanted to update that i think i have it in the right place now… but it’s not restricting to category:

    $content = preg_replace(“/AND post_date_gmt post2cat.”category_id in (1,2,3)”, $content);

    at least this does not bring up errors, but it doesn’t make the future posts show up either. not sure what to try next. it looks like greek to me.

    thanks for any help you have time to offer.

  8. very sorry for all the comments.

    i had a brainwave and realised (duh) that i could control the restriction in the templates. profusely sorry for cluttering your page! you can delete them if you like!

    thank you.

Laisser un commentaire

Votre adresse de messagerie ne sera pas publiée. Les champs obligatoires sont indiqués avec *

Ce site utilise Akismet pour réduire les indésirables. En savoir plus sur comment les données de vos commentaires sont utilisées.