Tips and Tricks HQ Support Portal › Forums › WP eMember › WP eMember General Questions › Hiding posts rather than requiring login
Tagged: login
- This topic has 8 replies, 3 voices, and was last updated 13 years, 9 months ago by amin007.
-
AuthorPosts
-
October 21, 2010 at 3:59 am #2070drlidbomMember
I’m looking for a way to not show certain posts at all, rather than display a message that someone must login to view the content. Is there a way not to show posts if a user is not logged in?
October 21, 2010 at 5:15 am #25651amin007ParticipantThis will have to come from a template (WordPress theme) level as the theme is what lists all the posts in your blog.
So you should be able to read this post to learn how you can check if a member is logged in or not then add an if condition to where the post gets displayed in the theme:
How to get member id and his details (retrieve member details)
Does that make sense?
October 21, 2010 at 6:18 pm #25652drlidbomMemberYes, but how can I tell if the post is a protected post or not?
October 22, 2010 at 6:55 am #25653amin007ParticipantI see… I think if we can add in a function in eMember that takes a post ID and tells you if the post is protected or not may be a solution for this. I will look into it.
October 22, 2010 at 11:39 am #25654drlidbomMemberThanks…please keep me posted.
As an aside, there would still be an issue with pagination or number of returned results, because the post query would return x results to loop over and then the user (if they were not logged in) would see x – y posts, where y is the number of protected posts.
Thoughts?
October 23, 2010 at 12:47 am #25655amin007ParticipantThis is the code that you can put in your functions.php file and use it to find out if a post is protected or not:
function eMember_is_post_protected ($post_id)
{
global $wpdb;
$wpdb->prefix . "wp_eMember_membership_tbl";
$query = "SELECT post_list FROM " . $wpdb->prefix . "wp_eMember_membership_tbl WHERE id = 1;";
$post_list = unserialize($wpdb->get_var($wpdb->prepare($query)));
if(!$post_list) return false;
return in_array($post_id, $post_list);
}Now, you can use the above function like the following (this is just an example):
if(eMember_is_post_protected ($post->ID))
echo "Post is protected";
else
echo "Post is not protected";October 23, 2010 at 12:54 am #25656amin007ParticipantYeah the pagination would be an issue. Basically, anything that gets controlled by the theme will have to be controlled on a theme level (this is why eMember doesn’t have options to do anything like this)
February 11, 2011 at 3:02 pm #25657TuttieMemberI am using http://www.elegantthemes.com/preview/Magnificent/ and would like to do the same. Hide pages and posts and only viewable after login. Also hide the pages that led them to the purchase aka hte squeeze pages.
February 12, 2011 at 3:40 am #25658amin007ParticipantYou need to apply similar changes that I mentioned in the post above to the theme. I am not familiar with that theme so cannot tell you exactly where to change.
-
AuthorPosts
- You must be logged in to reply to this topic.