Site icon Hip-Hop Website Design and Development

search with pagination not working as expexted

problem image

why this url pattern is taking me to 404 page where i saw in some other sites this same pattern works fine with search and paginate please help me i am new to wordpress and dont know why this is happening anyone who is experienced can tell me whats wrong here looking for helpfull answers , thanks in advance

$search = get_query_var("s");
$page_num = get_page_num();

$query = new WP_Query(array(
    "posts_per_page" => 4,
    "paged" => $page_num,
    "post_type" => "post",
    "s"     => $search
));   

get_page_num in functions.php

function get_page_num(){
    $name = is_front_page() ? "page":"paged";
    $page = get_query_var($name);
    $page = esc_html($page);
    $page = $page ? $page:1;
    return $page;
}