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.

Display posts based on Custom Capability

Home Forums Community Forum Display posts based on Custom Capability

This topic contains 2 replies, has 2 voices. Last updated by  Jeremy Michiels 4 years, 6 months ago.

Topic Author Topic
Posted: Friday Jul 6th, 2012 at 2:58 pm #18499

List Of Topic Replies

Viewing 2 replies - 1 through 2 (of 2 total)
Author Replies
Author Replies
Posted: Saturday Jul 7th, 2012 at 4:50 pm #18576
Eduan
Username: Eduan
Moderator

Hello Jeremy,

Have you looked into advanced conditionals?

You can find some documentation under Dashboard -› s2Member® -› API / Scripting -› Advanced PHP Conditionals.

You can find a video on it here:
Video » s2Member (Advanced Conditionals)

Hope this helps. :)

Posted: Monday Jul 9th, 2012 at 3:55 pm #18700

Thanks Eduan. I had looked through all the Advanced Conditionals previously and could not figure it out using the examples provided. However your reply did get me thinking in a different way. I decided to simply add a category labled “Private” and use that coupled with the custom capabilities to create a template page that would should only personal content for the logged in user. Here is the code:


  <?php
     query_posts( $query_string . '&cat=47' ); // gets only posts from the private category (check your id)
     global $more; $more = 0;
     
     if ( have_posts() ) {
         while ( have_posts() ) {
         the_post();
             if ( is_permitted_by_s2member()) {  // only if the user is permitted to view the post will it be displayed
             ....post info here...
             }
          }
     } else {
	  echo '<p>You have no private posts.</p>';
	 }
 ?>
 

The only drawback of this method is that it does not check to see if the user actually has a private post prior to getting into the loop. That is, there could be private posts for other members but not this one. In that case, have_posts will be true and the else element will not display. I’ll have to work on that piece later. Not sure how to get that to work off the bat.

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.