非常感谢你。与此同时,我发现了如何解决。我当前的代码如下:
class CustomSearch
{
public function __construct()
{
add_action(\'init\', array($this, \'init\'));
add_shortcode(\'custom_search\', array($this, \'shortcode_handler\'));
}
public function init()
{
if (!empty($_POST[\'nonce_custom_form\']))
{
if (!wp_verify_nonce($_POST[\'nonce_custom_form\'], \'handle_custom_form\'))
{
die(\'You are not authorized to perform this action.\');
} else
{
$error = null;
if (empty($_POST[\'workingLanguage\']) && empty($_POST[\'workingArea\']) )
{
$error = new WP_Error(\'empty_error\', __(\'Please enter search request.\', \'floh\'));
wp_die($error->get_error_message(), __(\'CustomSearch Error\', \'floh\'));
}
else
{
$rd_args = array(
\'post_type\' => \'page\',
\'meta_query\' => array(
\'relation\' => \'AND\',
array(
\'key\' => \'name\',
\'value\' => $_POST[\'name\'],
\'compare\' => \'LIKE\'
),
array(
\'key\' => \'email\',
\'value\' => $_POST[\'email\'],
\'compare\' => \'LIKE\'
)
)
);
$rd_query = new WP_Query( $rd_args );
$posts = $rd_query->posts;
// The Loop
if( $rd_query->have_posts() ) {
echo \'<ul>\';
while ( $rd_query->have_posts() ) {
$rd_query->the_post();
echo \'<li>\'.get_the_title().\'</li>\';
}
echo \'</ul>\';
} else {
// no posts found
}
}
}
}
}
function shortcode_handler($atts)
{
return "<form method=\'post\' action=\'\'>
<p>Name: <input name=\'name\' type=\'text\' value=\'\' /></p>
<p>eMail: <input name=\'email\' type=\'text\' value=\'\' /></p>
" . wp_nonce_field(\'handle_custom_form\', \'nonce_custom_form\') . "
<input type=\'submit\' value=\'Submit\'/>
</form>";
}
}
$CustomSearch = new CustomSearch();
现在,我必须了解如何将列表附加到表单下方的searchpage。或者更好的是,如何将结果$rd\\U结果“发送”到默认搜索页面?
更新:我学会了使用return而不是echo,这样输出的顺序就正确了。(我不知道为什么我开始使用echo)
最佳regardsFloh