I have created a custom post-type ‘Clients’ where admin user can create new clients, add pictures and details to post, then password protect the page so only a particular client can access the content.
For displaying content of this post-type on the front end, I’m using a single-clients.php template. It displays the content perfectly, but the password protect function does not display the form and hide the content, even if I’m in a different browser, cache cleared/logged out of WordPress (viewing it as a regular end-user would).
What might I be doing wrong here?
<?php get_header(); ?>
<div class="container-client">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
Display all fields and content for post-type
<?php endif; ?>
<?php endwhile; else: ?>
<div class="alert-box error">Sorry, this page no longer exists :( — <a href="<?php bloginfo('url'); ?>/">Back to home</a></div>
<?php endif; ?>
</div>
<?php get_footer(); ?>
This is roughly how my single-clients.php page is setup. Is there any way to manually display the password function so that when end-user visits page, the content is hidden and password form is displayed?
I had exactly this problem and after some trying and reading the codex I came up with this solution:
This way the page is only rendered in the custom sinlge view after entering a password, if it is password protected.