2017-01-27 17 views
0

私は検索結果の一部の変数を更新するのに$_GETを使用していますが、結果の次のページをクリックすると1ページから同じ投稿が表示されます。問題が何であるか把握しているようだ。

<?php 
if(isset($_GET['submit'])){ 
    $carigot = $_GET['car']; 
    $searchm = $_GET['s']; 
} 
?> 

<?php 

$custom_query_args = array(
    'post_type' => 'post', 
    'posts_per_page' => '1', 
    'meta_query' => array(
     array(
      'key'  => 'CurrentLocation', 
      'value' => $searchm, 
      'compare' => '=', 
     ), 
     array(
      'key' => 'CarIWant', 
      'value' => $carigot, 
      'type' => '', 
      'compare' => '=', 
       ), 
    ), 
    'paged' => get_query_var('paged') ? get_query_var('paged') : 1, 
); 

$custom_query = new WP_Query($custom_query_args); 

$temp_query = $wp_query; 
$wp_query = NULL; 
$wp_query = $custom_query; 

if ($custom_query->have_posts()) : 
    while ($custom_query->have_posts()) : 
     $custom_query->the_post(); 
     get_template_part('template-parts/post/content', 'excerpt'); 
    endwhile; 
endif; 
// Reset postdata 
wp_reset_postdata(); 

next_posts_link('Next', $custom_query->max_num_pages); 
previous_posts_link('Previous'); 


$wp_query = NULL; 
$wp_query = $temp_query; 
?> 

答えて

0

クエリを上書きしています。 new WP_Queryを2回呼び出して、同じ変数に割り当てていることに注意してください。あなたのページネーションをオリジナルに移動し、そのページングを取り除く。

$custom_query_args = array(
     'post_type' => 'post', 
     'posts_per_page' => '1', 
     'meta_query' => array(
      array(
       'key'  => 'CurrentLocation', 
       'value' => $searchm, 
       'compare' => '=', 
      ), 
      array(
       'key' => 'CarIWant', 
       'value' => $carigot, 
       'type' => '', 
       'compare' => '=', 
        ), 
     ), 
     'paged' => get_query_var('paged') ? get_query_var('paged') : 1, 
); 
+0

ご回答ありがとうございます。あなたのように私のコードを変更しましたが、問題はまだそこにあります。上記の投稿を編集して、私が今使っているコードを見せてください。あなたが正しく言ったことはすべてやったのですか? – Oscar

関連する問題