On the homepage:
<form method="post" action="">
<input type="password" name="passwordfield">
<input type="hidden" name="homepagepassword" value="1">
<input type="submit" value="Submit">
</form>
Place in functions.php ( create the file if it doesnt already exist and add <?php
at the top) or in a plugin file:
function doPasswordStuff(){
if(isset($_POST['homepagepassword'])){
$pass = $_POST['passwordfield'];
$q = new WP_Query( array( 'meta_key' => 'password_value', 'meta_value' => $pass));
if($q->have_posts()){
while($q->have_posts()){
$q->the_post();
wp_redirect(get_permalink());
die();
}
} else {
// oh dear, there isnt a post with this 'password', put a redirect to a fallback here
wp_redirect('http://www.google.com');
die();
}
wp_reset_query();
}
}
add_action('init','doPasswordStuff');
Add a custom field to your post with the key/name password_value
and the value being your password.
If you want to skip this step and use the password Wordpress uses to lock the post directly, you will need to use $wpdb
and an SQL query, and to hash the password your checking prior.
edit: I've updated this to use the 'init' hook, you can put the code in a plugin file instead of functions.php if you want this to be theme independent. ( Although you will still need to put the form markup somewhere ).