0
I developed a son theme based on Spacious, the problem is that when doing a search is returned that there are for example 20 results, on the first page I preview the first 10 results, however when advancing to page 2, I get a 404 error, and there are still posts to be displayed.
Permanent link settings are as: /%category%/%postname%/
In the archive search.php
I have the following search code:
$metas = array();
$is_author = false;
$is_keywords = false;
if( isset($_GET['searchin']) && !empty($_GET['searchin']) ){
if($_GET['searchin'] == 'articles'){
$types = array('article');
}
else if($_GET['searchin'] == 'articles-author'){
$is_author = true;
$types = array('article');
$metas[] = array(
'key' => 'wpcf-autores',
'value' => get_search_query(),
'compare' => 'LIKE',
);
}
else if($_GET['searchin'] == 'articles-keywords'){
$is_keywords = true;
$types = array('article');
$metas[] = array(
'key' => 'keywords',
'value' => get_search_query(),
'compare' => 'LIKE',
);
}
}
else{
$types = array('post', 'page');
}
$post_meta = $metas;
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
$default_posts_per_page = get_option( 'posts_per_page' );
$args = array(
'paged' => $paged,
'posts_per_page' => $default_posts_per_page,
'post_status' => 'publish',
'post_type' => $types,
'meta_query' => $post_meta
);
if( !$is_author && !$is_keywords ){
$args['s'] = get_search_query();
}
// The Query
$posts = new WP_Query( $args );
set_query_var( 'max_num_pages', $posts->max_num_pages );
To display the pagination I make a call to the following function that is in my file functions.php
:
function wordpress_pagination(){
global $wp_query;
$max_num_pages = get_query_var( 'max_num_pages', null ); //value set in search.php
if( is_null($max_num_pages) ){
$max_num_pages = $wp_query->max_num_pages;
}
$big = 999999999;
if( $max_num_pages > 1){
echo paginate_links(array(
//'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => 'page/%#%/',
'current' => max( 1, get_query_var('paged') ),
'total' => $max_num_pages,
'prev_text' => '<i class="fa fa-angle-double-left" aria-hidden="true"></i>',
'next_text' => '<i class="fa fa-angle-double-right" aria-hidden="true"></i>',
));
}
set_query_var( 'max_num_pages', null );
}
I left commented the attribute base
, because when that line is discolored it keeps appearing #038;
between the GET parameters.
The archive .htaccess
is the default of wordpress.
Can someone please help me, I’ve researched several places and for now nothing...