[上http://wordpress.stackexchange.com溶液s_ha_dum]
我试图引导用户根据在岗位设置中输入密码的一定职务。 我几乎工作的代码:
窗体页上:
<form method="post" action="">
<input type="password" name="passwordfield">
<input type="hidden" name="homepagepassword" value="1">
<input type="submit" value="Submit">
</form>
代码的functions.php
function doPasswordStuff(){
if(isset($_POST['homepagepassword'])){
$post_password = $_POST['passwordfield'];
$post_id = $wpdb->get_var( $wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_password = %s", $post_password) );
$q = new WP_Query( 'p=$post_id' );
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');
但是我得到致命错误(致命错误:调用一个成员函数get_var()一个非对象)在这条线:
$ POST_ID = $ wpdb-> get_var($ wpdb->准备( “SELECT ID FROM $ wpdb->帖子WHERE post_password =%d”,$ post_password));
如果真的很感激,如果有人来看看:)谢谢!