WordPress plugins not working correctly

I created a function that uses the built-in paginate_links function.

But pagination does not work correctly because the URL is spelled incorrectly.

The url I want looks like this: domain.com/properties/page/2/?foo=bar

Display URL: domain.com/properties/?foo=bar/page/2/

Here is my code

 function paginate($max_num_pages) { global $wp_query, $wp_rewrite; $wp_query->query_vars['page'] > 1 ? $current = $wp_query->query_vars['page'] : $current = 1; $pagination = array( 'base' => @add_query_arg('page','%#%'), 'format' => '', 'total' => $max_num_pages, 'current' => $current, 'show_all' => true, 'end_size' => 1, 'mid_size' => 2, 'prev_next' => True, 'prev_text' => __('Β« Previous'), 'next_text' => __('Next Β»'), 'type' => 'plain', 'add_args' => false, 'add_fragment' => '' ); if( $wp_rewrite->using_permalinks() ) $pagination['base'] = user_trailingslashit( trailingslashit( remove_query_arg( 's', get_pagenum_link( 1 ) ) ) . 'page/%#%/', 'page' ); if( !empty($wp_query->query_vars['s']) ) $pagination['add_args'] = array( 's' => get_query_var( 's' ) ); echo paginate_links( $pagination ); } 
+4
source share
2 answers

This is what ultimately works for me.

I had to change $wp_query->query_vars to paged , and I removed the line that checked if I used perma links if ( $wp_rewrite->using_permalinks() ) $pagination['base'] = user_trailingslashit( trailingslashit( remove_query_arg( 's', get_pagenum_link( 1 ) ) ) . 'page/%#%/', 'paged' );

 function paginate($max_num_pages) { global $wp_query, $wp_rewrite; $wp_query->query_vars['paged'] > 1 ? $current = $wp_query->query_vars['paged'] : $current = 1; $pagination = array( 'base' => @add_query_arg('paged','%#%'), 'format' => '', 'total' => $max_num_pages, 'current' => $current, 'show_all' => true, 'end_size' => 1, 'mid_size' => 2, 'prev_next' => True, 'prev_text' => __('Β« Previous'), 'next_text' => __('Next Β»'), 'type' => 'plain', 'add_args' => false, 'add_fragment' => '' ); //if ( $wp_rewrite->using_permalinks() ) $pagination['base'] = user_trailingslashit( trailingslashit( remove_query_arg( 's', get_pagenum_link( 1 ) ) ) . 'page/%#%/', 'paged' ); if ( !empty($wp_query->query_vars['s']) ) $pagination['add_args'] = array( 's' => get_query_var( 's' ) ); echo paginate_links( $pagination ); } 
+3
source

According to the documentation for paginate_links , the default format value is similar to what you need, but you override this value by setting 'format' => '' .

Try removing this option or setting it for what you need: 'format' => '?foo=bar%#%'

+1
source

Source: https://habr.com/ru/post/1493305/


All Articles