Разбивка страниц всегда 2 страницы

У меня проблема с разбиением на страницы, что она отлично работает с страницей блога, но когда я хочу показать пользовательский тип сообщения, он всегда показывает две страницы, даже если содержит только одно сообщение.

PS Я изменил свою функцию, чтобы отображать страницы по выбору, но до этого это была та же проблема.

enter code here if ( !function_exists( 'wpbeginner_numeric_posts_nav' ) ) { function wpbeginner_numeric_posts_nav() { if( is_singular() ) return; global $wp_query; /** Stop execution if there's only 1 page */ if( $wp_query->max_num_pages <= 1 ) return; $paged = get_query_var( 'paged' ) ? absint( get_query_var( 'paged' ) ) : 1; $max = intval( $wp_query->max_num_pages ); /** Add current page to the array */ if ( $paged >= 1 ) $links[] = $paged; /** Add the pages around the current page to the array */ if ( $paged >= 3 ) { $links[] = $paged - 1; $links[] = $paged - 2; } if ( ( $paged + 2 ) <= $max ) { $links[] = $paged + 2; $links[] = $paged + 1; } echo '<div class="navigation"><h3 class="filtttl">Pages</h3> ';?> <form action="<?php bloginfo('url'); ?>" method="get" class="filterform page"> <input type="hidden" name="post_type" value="voyage" /> <input type="hidden" id="s" name="s" value="" /> <select name="paged" id="pageselect" onchange="form.submit()"> <?php echo ' . "\n"'; /** Previous Post Link */ /*if ( get_previous_posts_link() ) printf( '<option>%s</option>' . "\n", get_previous_posts_link() );*/ /** Link to first page, plus ellipses if necessary */ if ( ! in_array( 1, $links ) ) { $class = 1 == $paged ? ' class="active"' : ''; printf( '<option%s><a href="%s">%s</a></option>' . "\n", $class, esc_url( get_pagenum_link( 1 ) ), '1' ); if ( ! in_array( 2, $links ) ) echo '<option>…</option>'; } /** Link to current page, plus 2 pages in either direction if necessary */ sort( $links ); foreach ( (array) $links as $link ) { $class = $paged == $link ? ' class="active"' : ''; printf( '<option%s><a href="%s">%s</a></option>' . "\n", $class, esc_url( get_pagenum_link( $link ) ), $link ); } /** Link to last page, plus ellipses if necessary */ if ( ! in_array( $max, $links ) ) { if ( ! in_array( $max - 1, $links ) ) echo '<option>…</option>' . "\n"; $class = $paged == $max ? ' class="active"' : ''; printf( '<option%s><a href="%s">%s</a></option>' . "\n", $class, esc_url( get_pagenum_link( $max ) ), $max ); } /** Next Post Link */ /*if ( get_next_posts_link() ) printf( '<option>%s</option>' . "\n", get_next_posts_link() );*/ echo '</select></form></div>' . "\n"; } } 

А на странице поиска это мой код.

 enter code here <div class="intro"> <div class="leftsearchform"> <form method="get" role="search" action="<?php bloginfo('url'); ?>" class="searchpage"> <h2 class="srchttl">Rechercher votre voyage</h2> <input type="text" class="dest" name="dest" placeholder="Destination" /> <input type="text" class="dep" name="dep" placeholder="Départ" /> <input type="text" class="arr" name="arr" placeholder="Arrivée" /> <input type="hidden" name="post_type" value="voyage" /> <input type="hidden" id="s" name="s" value="" /> <input type="submit" class="sub" value="Rechercher" /> </form> </div><!-- !leftsearchform --> <div class="resultsearch"> <div class="filtersrch"> <?php $sort= $_GET['sort']; if($sort == "Croissant") { $filter= "asc"; } if($sort == "Decroissant") { $filter= "desc"; } $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1; ?> <?php $temp = $voy_query; $voy_query= null; $args = array( 'post_type' => 'voyages', 'posts_per_page' => 4, 'orderby' => 'meta_value_num', 'meta_key' => $prx, 'order' => $filter, 'paged' => $paged, 's' =>$s, ); $voy_query = new WP_Query($args); ?> <h3 class="nbrrzlt"><?php echo $voy_query ->found_posts .' résultats.'; ?></h3> <h3 class="filtttl">Prix</h3> <form action="" method="get" class="filterform"> <!--<input type="hidden" name="post_type" value="voyage" />--> <input type="hidden" id="s" name="s" value="" /> <select name="sort" id="sorting" onchange="form.submit()"> <option value="Croissant" <?php if ($sort == "Croissant"){ echo 'selected="selected"'; } ?> > Croissant</option> <option value="Decroissant" <?php if ($sort == "Decroissant"){ echo 'selected="selected"'; }?> selected="selected" >Decroissant</option> </select> </form> <?php wpbeginner_numeric_posts_nav(); ?> </div><!-- !filtersrch --> <?php if ($voy_query->have_posts()) : while ($voy_query->have_posts()) : $voy_query->the_post(); $post_id = get_the_ID(); . enter code here <div class="intro"> <div class="leftsearchform"> <form method="get" role="search" action="<?php bloginfo('url'); ?>" class="searchpage"> <h2 class="srchttl">Rechercher votre voyage</h2> <input type="text" class="dest" name="dest" placeholder="Destination" /> <input type="text" class="dep" name="dep" placeholder="Départ" /> <input type="text" class="arr" name="arr" placeholder="Arrivée" /> <input type="hidden" name="post_type" value="voyage" /> <input type="hidden" id="s" name="s" value="" /> <input type="submit" class="sub" value="Rechercher" /> </form> </div><!-- !leftsearchform --> <div class="resultsearch"> <div class="filtersrch"> <?php $sort= $_GET['sort']; if($sort == "Croissant") { $filter= "asc"; } if($sort == "Decroissant") { $filter= "desc"; } $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1; ?> <?php $temp = $voy_query; $voy_query= null; $args = array( 'post_type' => 'voyages', 'posts_per_page' => 4, 'orderby' => 'meta_value_num', 'meta_key' => $prx, 'order' => $filter, 'paged' => $paged, 's' =>$s, ); $voy_query = new WP_Query($args); ?> <h3 class="nbrrzlt"><?php echo $voy_query ->found_posts .' résultats.'; ?></h3> <h3 class="filtttl">Prix</h3> <form action="" method="get" class="filterform"> <!--<input type="hidden" name="post_type" value="voyage" />--> <input type="hidden" id="s" name="s" value="" /> <select name="sort" id="sorting" onchange="form.submit()"> <option value="Croissant" <?php if ($sort == "Croissant"){ echo 'selected="selected"'; } ?> > Croissant</option> <option value="Decroissant" <?php if ($sort == "Decroissant"){ echo 'selected="selected"'; }?> selected="selected" >Decroissant</option> </select> </form> <?php wpbeginner_numeric_posts_nav(); ?> </div><!-- !filtersrch --> <?php if ($voy_query->have_posts()) : while ($voy_query->have_posts()) : $voy_query->the_post(); $post_id = get_the_ID(); 

РЕДАКТИРОВАТЬ:

 // Load our function when hook is set add_action( 'pre_get_posts', 'rc_modify_query_get_design_projects' ); function rc_modify_query_get_design_projects( $query ) { // Check if on frontend and main query is modified if( ! is_admin() && $query->is_main_query() && $query->query_vars['post_type'] = 'voyages' ) { if ($query->is_search) { $query->set('meta_key', $prx); $query->set('meta_value', 'voyage[prx]'); } } } 

EDIT2:

 function textdomain_include_search($query) { if ( !is_admin() && $query->is_main_query() ) { if ($query->is_search) { $query->set('post_type', array( 'post', 'voyages' ) ); } } } add_action( 'pre_get_posts', 'textdomain_include_search' );