Skip to content

Instantly share code, notes, and snippets.

@nateplusplus
Forked from pablo-sg-pacheco/functions.php
Last active March 24, 2020 19:41
Show Gist options
  • Save nateplusplus/56ae36d2fe07ac75476eec20747ecd8d to your computer and use it in GitHub Desktop.
Save nateplusplus/56ae36d2fe07ac75476eec20747ecd8d to your computer and use it in GitHub Desktop.
Wordpress - Password protect a custom post type programmatically
<?php
//Password Protect programmatically
function passwordProtectPosts( $post_object ) {
//Checks if current post is a specific custom post type
if ( $post_object->post_type !== 'tutorial' ) {
return;
}
$post_object->post_password = 'your_password';
}
add_action( 'the_post', 'passwordProtectPosts' );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment