latest stable versions: v150827 (changelog)

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

Recent posts widget hide unrestricted posts

Home Forums Community Forum Recent posts widget hide unrestricted posts

This topic contains 5 replies, has 2 voices. Last updated by  Bruce 3 years, 4 months ago.

Topic Author Topic
Posted: Wednesday Aug 7th, 2013 at 10:37 am #55355

I have a sidebar widget that will only appear on restricted pages. Currently I have it showing the three most recent posts but I only want it to show the three most recent restricted posts so in effect hide unrestricted posts.

Is this possible? If so, how do I go about achieving this?

List Of Topic Replies

Viewing 5 replies - 1 through 5 (of 5 total)
Author Replies
Author Replies
Posted: Thursday Aug 8th, 2013 at 5:01 am #55406
Bruce
Username: Bruce
Staff Member

Is this possible? If so, how do I go about achieving this?

Yes, this is possible but you’ll need to use some fancy custom code. You can use this function to find out if a Post is protected by s2Member in PHP:

http://www.s2member.com/codex/stable/s2member/api_functions/package-functions/#src_doc_is_protected_by_s2member()

You’ll have to get your Posts, and only show the first 3 Posts that aren’t protected by s2Member that way.

That’s about as far as we can go with custom code. If you need further assistance, we recommend http://jobs.wordpress.net, or another freelance web site where WordPress® experts are offering their expertise through a bid on your project.
Posted: Thursday Aug 8th, 2013 at 7:01 am #55415

OK, I’ll do it that way if need be. I was aware of that function as I use it inside my main “loop” elsewhere but I was hoping it was possible to only retrieve protected posts rather than having to loop through all my posts, seems a bit of hack to me.

Surely it must be possible to do a more sophisticated solution. When I’m not logged in WP only returns the unprotected posts but when logged in it returns both unprotected and S2 protected posts. Why is it not possible for the get_posts or WP_Query to only return S2 protected posts? Logically it must be possible to set the $args parameters for this, surely?

Posted: Thursday Aug 8th, 2013 at 10:58 pm #55464
Bruce
Username: Bruce
Staff Member

Surely it must be possible to do a more sophisticated solution. When I’m not logged in WP only returns the unprotected posts but when logged in it returns both unprotected and S2 protected posts. Why is it not possible for the get_posts or WP_Query to only return S2 protected posts? Logically it must be possible to set the $args parameters for this, surely?

WordPress’s post queries do not take into account custom Post meta values (which is what s2Member uses to decide on if a Post/Page is protected) as far as I know. If you wanted to achieve that you’d need to create a custom SQL query using Regex, because s2Member stores its protections in a serialized array string, to accomplish this by looking at s2Member’s fields in your postmeta table, and that would be far more complicated than my above solution, as well as (probably) slower.

Posted: Friday Aug 9th, 2013 at 4:03 am #55486

No problem, I appreciate the insight and I agree the original solution you proposed appears to be much simpler. I will pursue that route. Thanks

I think it would be worth having this kind of functionality, surely it must be something that would be quite useful. I definitely think it would be good to have this. S2 should create the ability to do this in my opinion.

Posted: Monday Aug 12th, 2013 at 10:58 pm #55596
Bruce
Username: Bruce
Staff Member

S2 should create the ability to do this in my opinion.

Thanks for your thoughts. I’ll take this as a feature request, but I can’t say that it will be possible any time soon. This should really be a core WordPress feature. Otherwise all that s2Member can do is what I mentioned above in a function that wraps it. If it’s possible to accomplish creating a function that can query your database for these Posts, then I will see if our development team can add an API function for doing this. :-)

Viewing 5 replies - 1 through 5 (of 5 total)

This topic is closed to new replies. Topics with no replies for 2 weeks are closed automatically.

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

Contacting s2Member: Please use our Support Center for bug reports, pre-sale questions & technical assistance.