search with pagination not working as expected
Why is this url pattern taking me to a 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 don't know why this is happening anyone who is experienced can tell me whats wrong here looking for helpful 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;
}
Topic paginate-links pagination Wordpress
Category Web