Generally, forms should be handled on init
action or later (mainly in a plugin file, maybe in the theme’s functions.php file, never in a tempalte file), so you can have access to WP functions.
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();
}
}