WordPress How To Check If Post is Password Protected

Posted by Ankur Gandhi in Wordpress



wordpress-lock

wp Wordpress How To Check If Post is Password ProtectedHi Friends, Two days ago I was trying to solve one problem in my plugin IGIT Related Posts in which by default it was showing password protected posts so I was trying to make it like it will not show password protected posts in relates posts.It was not a big issue because I have to just insert one condition in sql query but today in this article I just want to give one idea that how can anyone check via PHP code in wordpress that post is password protected or not.

To check that if post is password protected or not then you have to do it via if condition shown below :

<?php

if (!empty($post->post_password)) { // if there's a password
// This code exceutes if your post dont have password.
}
?>



By this code you can check that post is password protected or not. If you have any problem in this then you can contact me .

You can follow any responses to this entry through the RSS 2.0 You can leave a response, or trackback.

  • zjawardz

    ill tyr the code thanks for posting