Paginare WordPress nefuncțională pe șablonul search.php
2 ian. 2018, 09:32:18
Vizualizări: 359
Voturi: 1
Am o mică problemă, paginarea nu funcționează pe search.php
.
Interoghez rezultatele cu wp_Query
folosind codul de mai jos,
Văd linkurile de pagină dar când le apăs primesc eroare 404.
Mi s-a spus că asta se întâmplă pentru că interoghez pe pagina search.php
.
Codul pe care îl folosesc este luat de pe wp code pagination, Este o interogare lungă dar cele mai importante sunt aceste două linii:
$paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1;
și
'paged' => $paged,
interogare completă
if (isset($_GET['reg-prop-search-form'])){
$paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1;
$args = array(
'posts_per_page' => 9,
's' => $_GET['s'],
'post_type' => 'property',
'paged' => $paged,
'meta_query' => array(
'relation ' => 'AND',
array(
'key' => 'prop_area',
'value' => $area,
'compare' => $area_val,
),
array(
'key' => 'prop_city',
'value' => $city,
'compare' => $city_val,
),
array(
'key' => 'prop_type',
'value' => $type,
'compare' => $type_val,
),
array(
'key' => 'prop_rooms',
'value' => array( $fromrooms, $torooms ),
'type' => 'numeric',
'compare' => 'BETWEEN',
),
array(
'key' => 'prop_store',
'value' => array( $fromfloor, $tofloor ),
'type' => 'numeric',
'compare' => 'BETWEEN',
),
array(
'key' => 'prop_price',
'value' => array( $min, $max ),
'type' => 'numeric',
'compare' => $equal,
),
),
);
};
acesta este loop-ul
$the_query = new WP_Query( $args );
.....
<?php if( $the_query->have_posts() ): ?>
<?php while( $the_query->have_posts() ) : $the_query->the_post(); ?>
<?php get_template_part( 'content', 'search' ); ?>
<?php endwhile; ?>
<div id="pagination">
<?php
$big = 999999999;
echo paginate_links( array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var('paged') ),
'total' => $the_query->max_num_pages
) );
?>
<?php echo paginate_links( $args ); ?>
</div>
<?php else : ?>
<?php get_template_part( 'no-results', 'search' ); ?>
<?php endif; ?>
<?php wp_reset_query(); // Restabilirea datelor globale ale postului afectate de the_post(). ?>
</div>
Comentarii
Întrebări similare
3
răspunsuri
0
răspunsuri