通常,表格应在init
操作或更高版本(主要在插件文件中,可能在主题的functions.php文件中,而不是在tempalte文件中),因此您可以访问WP函数。
add_action( \'init\', \'search_form_submit\' );
function search_form_submit(){
$task_name = isset($_GET[\'taskname\']) ? $_GET[\'taskname\'] : \'\';
$meta_key = \'wp_tasks\';
$args = array(
\'post_type\' => \'tasks\',
\'post_status\' => \'publish\',
\'posts_per_page\' => 5,
\'meta_query\' => array(
array(
\'key\' => $meta_key,
\'value\' => $task_name,
\'compare\' => \'LIKE\',
),
),
);
$query = new WP_Query($args);
if($query->have_posts()){
$query->the_post();
$data = get_post_meta(get_the_ID(),$meta_key,true);
}
}
$tasks_obj = new tasks();
if($_SERVER[\'REQUEST_METHOD\'] == \'GET\') {
$tasks_obj->search_form_submit();
}
}