Tips and Tricks HQ Support Portal › Forums › WP eMember › WP eMember General Questions › Hiding posts rather than requiring login
- This topic has 8 replies, 3 voices, and was last updated 12 years, 1 month ago by amin007.
October 21, 2010 at 3:59 am #2070
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 #25651
This 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 #25652
Yes, but how can I tell if the post is a protected post or not?October 22, 2010 at 6:55 am #25653
I 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 #25654
Thanks…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 #25655
This 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)
$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):
echo "Post is protected";
echo "Post is not protected";October 23, 2010 at 12:54 am #25656
Yeah 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 #25657TuttieMember
I 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 #25658
You 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.
- You must be logged in to reply to this topic.