Hi,
Check out the Advanced Query Conditionals.
Dashboard -> API /Scripting -> Advanced Query Conditionals
Advanced Query Conditionals ( some PHP scripting required )
s2Member provides several built-in API Functions that are tailored to meet the needs of developers integrating s2Member into their themes. Such as: is_protected_by_s2member($id, "[category,tag,post,page,singular,uri]"), is_permitted_by_s2member($id, "[category,tag,post,page,singular,uri]"), is_category_protected_by_s2member($cat_id), is_category_permitted_by_s2member($cat_id), is_tag_protected_by_s2member($tag_id [slug or tag name]), is_tag_permitted_by_s2member($tag_id [slug or tag name]), is_post_protected_by_s2member($post_id), is_post_permitted_by_s2member($post_id), is_page_protected_by_s2member($page_id), is_page_permitted_by_s2member($page_id), is_uri_protected_by_s2member($uri [or full url]), is_uri_permitted_by_s2member($uri [ or full url]).
In addition, there are two special functions that can be applied by theme authors before making custom queries: attach_s2member_query_filters(), detach_s2member_query_filters(). These can be used before and after a call to query_posts() for example. s2Member will automatically filter all protected content ( not available to the current User/Member ).
- Code: Select all
Example #1: Pre-filtering custom queries in WordPress®.
<?php
attach_s2member_query_filters();
query_posts("posts_per_page=5");
if (have_posts()):
while (have_posts()):
the_post();
/*
Protected content will be excluded automatically.
( based on the current User/Member status )
*/
endwhile;
endif;
wp_reset_query();
detach_s2member_query_filters();
?>
Example #2: OR, instead of pre-filtering; check Access Restrictions in The Loop.
<?php
detach_s2member_query_filters();
query_posts("posts_per_page=5");
if (have_posts()):
while (have_posts()):
the_post();
if(!is_permitted_by_s2member())
continue;
/* Skip it. The current User/Member has NO access. */
endwhile;
endif;
wp_reset_query();
?>