Page 1 of 1

restrict only older posts - based on age

PostPosted: May 11th, 2011, 4:59 pm
by arthomas
Hello guys

Is it possible to restrict posts based on age?

Case:
I want to offer news to everybody, but archives only to paid members, archives would be considered all posts older than 3 weeks or a month.
I think some newspapers have this model.

Is it currently possible? its not any particular date, just 3 weeks from today, or so.

I think its a very simple and interesting way to get people to pay while keeping your general readership happy.

Re: restrict only older posts - based on age

PostPosted: May 11th, 2011, 5:24 pm
by Cristián Lávaque
Yeah, I agree it's an interesting way to doing it. :)

Well, you could use s2Member conditionals to check that the user is a paid member and check the time the post was published too, and show it based on that.

WP Admin -> s2Member -> API / Scripting
http://www.s2member.com/api-scripting-overview-video/
http://www.s2member.com/advanced-conditionals-video/
https://codex.wordpress.org/Template_Tags#Post_tags

Re: restrict only older posts - based on age

PostPosted: May 11th, 2011, 5:34 pm
by arthomas
Thanks for your answer.
well :o
I am in no way well versed in PHP. this seems quite complicated.

Isn't there a simple way to do it?
Maybe it can be added to a future version. I guess its not a too obscure feature, probably many people will use it.

Or maybe you can give the right snippet of code.

Thanks anyway

Re: restrict only older posts - based on age

PostPosted: May 11th, 2011, 8:43 pm
by Cristián Lávaque
I haven't tested it, but I think it'd be something like this:

Code: Select all
<?php // Paid member or post newer than 30 days: show.
if (current_user_can('access_s2member_level1') || (time() - get_the_time('U')) < 2592000) { ?>
    
    Here goes the post...

<?php } ?>


Of course you'd need to customize it further to present something different for those that can't see the post.

If you don't know enough PHP to achieve the customization you want, I suggest you get a freelance developer to help you at a place like jobs.wordpress.net, take a look here viewforum.php?f=37

I hope that helps. :)