Skip to main content
deleted 508 characters in body; edited title
Source Link
mmm
  • 3.8k
  • 3
  • 16
  • 22

Wordpress Rewrite Rules For Search Page (Pagination Not Working) WordPress rewrite rules for pagination on search page

function Theme_pagination() {           
         
    if( (!empty($options['extra_pagination']) && $options['extra_pagination'] == '1' ) {
 
                 
        global $wp_query;  

                 
        $total_pages = $wp_query->max_num_pages;  

                 
        if ($total_pages > 1){  
 {
               
            $current_page = max(1, get_query_var('paged'));  

                 
            echo '<div id="pagination">';
 
                 
            echo paginate_links(array(  
                              'base' => get_pagenum_link(1) . '%_%',  
                              'format' => '/page/%#%',  
                              'current' => $current_page,  
                              'total' => $total_pages,  
                            ));    
                            echo  '</div>';         
                        }  
                    }
           } else{   
 {
         
        if( (get_next_posts_link() || get_previous_posts_link() ) { 
                echo '<div class="pagination col-lg-12">';

 
            
            if ( get_previous_posts_link() ) : ?>
                <div class="next-post margint20 button pull-left "><">
                    <?php previous_posts_link( __( 'NEWER POST ', 'Themes-fm' ) ); ?></div>>
                <?php endif;
/div>
            <?php endif;
   if ( get_next_posts_link() ) : ?>
      
           <div class="prev-post margint20 button pull-right"><?phpif next_posts_link( __get_next_posts_link( 'OLDER POST', 'Themes-fm' ) ); : ?></div>>
                <?php endif;<div 


 class="prev-post margint20 button pull-right">
             echo  '</div>';         
 <?php next_posts_link( __( 'OLDER POST', 'Themes-fm' ) ); ?>
    }
        }
    }
}

Here's the quick recap of the problem:

example.com</?s=catdiv>
(Let's say there are 10 posts matching to cat keyword with 5 posts per page on search<?php results)endif;
Results: 5 posts on the first page>Clicked on Older Posts button and next 5 posts.
example.com/store/cat
Results: First 5 posts on the first page>clicked on Older posts and pageecho says'</div>';
 "No Posts Founds As Per Your Search Terms"
}
I need to do something to pagination or the rewrite rule? I 
 don't have any idea what}
 to do next... any idea?
Thanks in advance... :)}

Here's the quick recap of the problem:

example.com/?s=cat (Let's say there are 10 posts matching to cat keyword with 5 posts per page on search results)
Results: 5 posts on the first page>Clicked on Older Posts button and next 5 posts.
example.com/store/cat
Results: First 5 posts on the first page>clicked on Older posts and page says "No Posts Founds As Per Your Search Terms"

I need to do something to pagination or the rewrite rule? I don't have any idea what to do next... any idea? Thanks in advance... :)

Wordpress Rewrite Rules For Search Page (Pagination Not Working)

function Theme_pagination() {           
            if( !empty($options['extra_pagination']) && $options['extra_pagination'] == '1' ){
 
                        global $wp_query;  

                        $total_pages = $wp_query->max_num_pages;  

                        if ($total_pages > 1){  
 
                          $current_page = max(1, get_query_var('paged'));  

                            echo '<div id="pagination">';
 
                            echo paginate_links(array(  
                              'base' => get_pagenum_link(1) . '%_%',  
                              'format' => '/page/%#%',  
                              'current' => $current_page,  
                              'total' => $total_pages,  
                            ));    
                            echo  '</div>';         
                        }  
                    }
            else{   
 
                if( get_next_posts_link() || get_previous_posts_link() ) { 
                echo '<div class="pagination col-lg-12">';

 
                if ( get_previous_posts_link() ) : ?>
                <div class="next-post margint20 button pull-left "><?php previous_posts_link( __( 'NEWER POST ', 'Themes-fm' ) ); ?></div>
                <?php endif;

                if ( get_next_posts_link() ) : ?>
                <div class="prev-post margint20 button pull-right"><?php next_posts_link( __( 'OLDER POST', 'Themes-fm' ) ); ?></div>
                <?php endif; 


                 echo  '</div>';         
             }
        }
    }
}

Here's the quick recap of the problem:

example.com/?s=cat
(Let's say there are 10 posts matching to cat keyword with 5 posts per page on search results)
Results: 5 posts on the first page>Clicked on Older Posts button and next 5 posts.
example.com/store/cat
Results: First 5 posts on the first page>clicked on Older posts and page says "No Posts Founds As Per Your Search Terms"

I need to do something to pagination or the rewrite rule? I don't have any idea what to do next... any idea?
Thanks in advance... :)

WordPress rewrite rules for pagination on search page

function Theme_pagination() {
     
    if (!empty($options['extra_pagination']) && $options['extra_pagination'] == '1') {
         
        global $wp_query;
         
        $total_pages = $wp_query->max_num_pages;
         
        if ($total_pages > 1) {
             
            $current_page = max(1, get_query_var('paged'));
             
            echo '<div id="pagination">';
             
            echo paginate_links(array(
                'base' => get_pagenum_link(1) . '%_%',
                'format' => '/page/%#%',
                'current' => $current_page,
                'total' => $total_pages
            ));
            echo '</div>';
        }
        
    } else {
         
        if (get_next_posts_link() || get_previous_posts_link()) {
            echo '<div class="pagination col-lg-12">';
            
            if (get_previous_posts_link()) : ?>
                <div class="next-post margint20 button pull-left ">
                    <?php previous_posts_link( __( 'NEWER POST ', 'Themes-fm' ) ); ?>
                </div>
            <?php endif;
             
            if (get_next_posts_link()) : ?>
                <div class="prev-post margint20 button pull-right">
                    <?php next_posts_link( __( 'OLDER POST', 'Themes-fm' ) ); ?>
                </div>
            <?php endif;
            
            echo '</div>';
        }
         
    }
    
}

Here's the quick recap of the problem:

example.com/?s=cat (Let's say there are 10 posts matching to cat keyword with 5 posts per page on search results)
Results: 5 posts on the first page>Clicked on Older Posts button and next 5 posts.
example.com/store/cat
Results: First 5 posts on the first page>clicked on Older posts and page says "No Posts Founds As Per Your Search Terms"

I need to do something to pagination or the rewrite rule? I don't have any idea what to do next... any idea? Thanks in advance... :)

edited tags
Link
Source Link

Wordpress Rewrite Rules For Search Page (Pagination Not Working)

So far, I need to build a custom search slug e.g by default its: example.com/?s=cat I changed it to example.com/store/query using following rewrite rules inside function.php file

function feed_dir_rewrite( $wp_rewrite ) {
    $feed_rules = array( 'store/(.+)' => 'index.php?s=' . $wp_rewrite->preg_index(1));
    $wp_rewrite->rules = $feed_rules + $wp_rewrite->rules;
}
add_filter( 'generate_rewrite_rules', 'feed_dir_rewrite' );   

Now, everything works fine, but pagination doesn't work at all, below is the pagination code:

function Theme_pagination() {           
            if( !empty($options['extra_pagination']) && $options['extra_pagination'] == '1' ){

                        global $wp_query;  

                        $total_pages = $wp_query->max_num_pages;  

                        if ($total_pages > 1){  

                          $current_page = max(1, get_query_var('paged'));  

                            echo '<div id="pagination">';

                            echo paginate_links(array(  
                              'base' => get_pagenum_link(1) . '%_%',  
                              'format' => '/page/%#%',  
                              'current' => $current_page,  
                              'total' => $total_pages,  
                            ));    
                            echo  '</div>';         
                        }  
                    }
            else{   

                if( get_next_posts_link() || get_previous_posts_link() ) { 
                echo '<div class="pagination col-lg-12">';


                if ( get_previous_posts_link() ) : ?>
                <div class="next-post margint20 button pull-left "><?php previous_posts_link( __( 'NEWER POST ', 'Themes-fm' ) ); ?></div>
                <?php endif;

                if ( get_next_posts_link() ) : ?>
                <div class="prev-post margint20 button pull-right"><?php next_posts_link( __( 'OLDER POST', 'Themes-fm' ) ); ?></div>
                <?php endif; 


                echo  '</div>';         
            }
        }
    }
}

Here's the quick recap of the problem:

example.com/?s=cat
(Let's say there are 10 posts matching to cat keyword with 5 posts per page on search results)
Results: 5 posts on the first page>Clicked on Older Posts button and next 5 posts.
example.com/store/cat
Results: First 5 posts on the first page>clicked on Older posts and page says "No Posts Founds As Per Your Search Terms"

I need to do something to pagination or the rewrite rule? I don't have any idea what to do next... any idea?
Thanks in advance... :)