Exclude the_content (); from page password protection

I use a page template to show custom post type.

All content from the custom post type should be password protected. I´d like to use the wordpress editor for some additional public information. Can I exclude the_content(); from wordpress password protection?

Read More

page-my-custom-post-type.php

// ================ PUBLIC AREA BEGINNS ================
<h4>Pubic-Area</h4>

<?php
if (have_posts()) : while (have_posts()) : the_post();
the_content();
endwhile; 
endif;
// ================ PUBLIC AREA ENDS ================   




// ================ PROTECTED AREA BEGINNS ================
if ( post_password_required() ) {
        echo get_the_password_form();
}
else {


$index = 'A';
$terms = get_terms('marke');

foreach ($terms as $term) {
    if($index != strtoupper(substr($term->name, 0, 1))) {
        $index = strtoupper(substr($term->name, 0, 1));

        echo '<h1>'. $index . '</h1>';
    }

    ?>
    <h2><?php echo $term->name; ?></h2>
    <?php $args = array( 'post_type' => 'cpt_auto', 'posts_per_page' => -1, 'orderby' => 'title', 'order' => 'ASC', 
        'tax_query' => array(
            array(
                'taxonomy' => 'marke',
                'field' => 'slug',
                'terms' => array($term->slug)
            )
        )
    );

    // ============================= OUTPUT ==============================
    $loop = new WP_Query( $args ); while ( $loop->have_posts() ) : $loop->the_post();
        the_title('<h3>', '</h3>');
        the_content();

    endwhile;

}
?>


<?php }
// ================ PROTECTED AREA ENDS ================
?>

Thanks
Ogni

Related posts

Leave a Reply

1 comment

  1. You can use the conditional tag if ( post_password_required() ) : for check, if a password required and then exclude the_content().

    // view content, only if password is required
    if ( post_password_required() )
        the_content();
    

    Also it is possible that you go about the global var $post

    if ( ! empty( $post->post_password ) ) :
    

    Ot, the last chance and not so fine, bute usefull is to enhance the query:

    AND post_password = ''