3

I am looking for a conditional to test simply if a post (custom post type, if it somehow makes a difference) is set to have password protection…persistently…regardless of whether user has accessed the post via the password or not.

post_password_required() only returns true if the user has not already entered the password

get_post_status() (though it does return a 'private' status if a post is private) only returns 'published' for a password-protected post

  • I think you have to check if $post->post_password is not empty – czerspalace Mar 5 '16 at 1:22
4

You could use

if(!empty($post->post_password)){
   // do some stuff
}

which is what the post_password_required() code does before checking the user's credentials against the password itself.

  • Thank you. Not sure why I didn't think about looking into the code of that function first! – Kerri Mar 8 '16 at 16:12
  • That's understandable - the function didn't do what you wanted it to! – Isaac Lubow Mar 10 '16 at 0:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.