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.

Show latest allowed posts for member level

Home Forums Community Forum Show latest allowed posts for member level

This topic contains 2 replies, has 2 voices. Last updated by  Paddy Ogee 3 years, 11 months ago.

Topic Author Topic
Posted: Wednesday Jan 16th, 2013 at 12:58 pm #37786

I am using this code in a footer to show latest posts. However, it only ALLOWS the latest 3 posts regardless of level, therefore, if a post from the latest 3 is not available to you, then it only shows that.

For instance, the latest 3 posts have one for general consumption and two restricted. If you are not logged in, then you only see one post.

Obviously that behaviour from a member point of view is fine, but I would like to show the 3 latest allowed posts for the member level.

Any help appreciated.

<?php detach_s2member_query_filters(); ?>
<?php query_posts('showposts=3'); ?>
<?php while (have_posts()) : the_post(); ?>
<?php if(!is_permitted_by_s2member())
 continue;
 ?>
 

List Of Topic Replies

Viewing 2 replies - 1 through 2 (of 2 total)
Author Replies
Author Replies
Posted: Thursday Jan 17th, 2013 at 1:44 pm #37910
Staff Member

Thanks for reporting this important issue.

This is actually the intended functionality. At least, in the way you’ve implemented this. Instead of removing s2Member query filters (which is what you actually want in this case), leave them on, and don’t use the is_permitted_by_s2member() function at all.

<?php attach_s2member_query_filters(); ?>
<?php query_posts('showposts=3'); ?>
<?php while (have_posts()) : the_post(); ?>

You will also want to make sure s2Member query filters (i.e. Alternative View Restrictions) are enabled.
See: Dashboard -› s2Member® -› Restriction Options -› Alternative View Protection

s2Member’s query filters will achieve what you need, because they filter the query itself, instead of you filtering the results from a query that was unfiltered, which is what is happening in the code you posted for review.

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

Please let us know if problems persist :-)

Posted: Thursday Jan 17th, 2013 at 2:53 pm #37920

Thanks very much for the reply, that worked perfectly.

Viewing 2 replies - 1 through 2 (of 2 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.