更新时间:2023-11-11 14:46:22
在此之前全局化 $wpdb
globalize $wpdb before this
全局 $wpdb
$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');
此外,***使用小写的表/列名称
Also it is a best practise to use lowercase table/column names
然后像这样重定向
have_posts() ) : while ( $q->have_posts() ) : $q->the_post();?>
wp_redirect( the_permalink() );
还使用 http 状态代码作为 wp_redirect() 的第二个参数这可能会有所帮助HTTP 状态代码
Also use a http status code as the second parameter to wp_redirect() This might be helpful HTTP STATUS CODES