WordPress.org

Ready to get started?Download WordPress

Forums

WordPress Pagination Script Issue (1 post)

  1. Manan
    Member
    Posted 5 months ago #

    Hello Everyone :)

    I have question regarding pagination script. Currently I am using Simple Pagination for display custom post type records.

    Everything is working good but when I pass some variable from URL and click to second page, next record is not displaying. Why I am not getting second results.

    I am getting result if URL is:
    http://localhost/example/my-search/
    or
    http://localhost/example/my-search/page/2/

    I am not getting result if URL is:
    http://localhost/example/my-search/page/2/?books=Internet&submit=search

    Please I need your help to fix this issue.

    My Code:

    <?php
    	$args = array (
    		'post_type' => 'book',
    		'post_status' => 'publish',
    		'paged' => $paged,
    		'posts_per_page' => -1
    	);
    
    	$temp = $wp_query; //Assign ordinal query to temp variable for later use
    	$wp_query = null;
    	$wp_query = new WP_Query($args);
    
    	echo '<div class="result-count">Showing all '.$wp_query->post_count.' results</div>';
    
    			if ( $wp_query->have_posts() ) :
    				while ( $wp_query->have_posts() ) : $wp_query->the_post();
    
    					echo '<div class="entry-content">';
    						the_title();
    					echo'</div>';
    
    				endwhile;
    			endif;
    	echo '</div>';
    ?>
    <nav>
    	<?php
        	if(function_exists('wp_simple_pagination')) {
                wp_simple_pagination();
            }
        ?>
    
       <?php
            $wp_query = null;
            $wp_query = $temp; // Reset
       ?>
    </nav>

Reply

You must log in to post.

About this Topic