这让我朝着正确的方向前进。这是我想到的。我决定创建一个短代码,这样我就可以把它放到任何需要的地方。使用get\\u page\\u by\\u title()还可以查找帖子,即使它们的帖子类型在传统搜索中是隐藏的。
function esm_search($atts) {
extract(shortcode_atts(array(
"label_codeword" => \'Codeword\',
"label_submit" => \'Submit\'
), $atts));
if ($_SERVER[\'REQUEST_METHOD\'] == \'POST\') {
$error = false;
foreach ($_POST as $field => $value) {
if (get_magic_quotes_gpc()) {
$value = stripslashes($value);
}
$form_data[$field] = strip_tags($value);
}
if( $form_data[\'codeword\'] != "") {
$esmID = get_page_by_title($form_data[\'codeword\'],"","esm" );
if( $esmID ) {
wp_redirect( get_permalink( $esmID ) );
}else{
$result = \'That codeword doesn\\\'t exist.\';
}
}else{
$result = "Please enter a codeword.";
}
}
if( $result != "" ) {
$info = \'<div class="info">\'.$result.\'</div>\';
}
$esm_form = \'<form method="post" action="\'.get_permalink().\'">
<div>
<input type="text" name="codeword" id="esm_codeword" size="6" maxlength="6" value="\'.$form_data[\'codeword\'].\'" />
</div>
<div>
<input type="submit" value="Sumbit" name="send" id="esm_send" />
</div>
</form>\';
if($sent == true) {
return $info;
} else {
return $info.$esm_form;
}
}
我使用的P.S
this tutorial 作为代码的模板。