WordPress.org

Ready to get started?Download WordPress

Forums

Check in the Loop if a post is password protected (4 posts)

  1. Elan42.com
    Member
    Posted 4 years ago #

    Hi guys.

    I want to add a "lock" in the excerpt of a post if the post is password protected.

    Do someone know a way to know, in a loop, if the post is password protected?

    How do I force WP to show me the excerpt of a Password-Protected post?

  2. MichaelH
    Member
    Posted 4 years ago #

    Got this from http://comox.textdrive.com/pipermail/wp-testers/2008-November/010138.html

    <?php
    if (!empty($post->post_password)) { // if there's a password
    if ($_COOKIE['wp-postpass_' . COOKIEHASH] != $post->post_password) {  // and it doesn't match the cookie
    echo 'display of excerpt:' . $post->post_excerpt;
    }
    }
    ?>
  3. Elan42.com
    Member
    Posted 4 years ago #

    The "if" block works, it understands if a post is password protected.

    However $post->post_excerpt;
    is empty.

    Do someone knows why? Do I have to take some global variable before this code?

  4. MichaelH
    Member
    Posted 4 years ago #

    Could be you are talking about the 'manufactured' Excerpt so use template tag, the_excerpt() instead.

Topic Closed

This topic has been closed to new replies.

About this Topic