Custom Search Page Pagination Not Working

You’re running into a conflict between your replacement query and the default search query that’s running behind the scenes. Instead of running a new WP_Query, try modifying the default query by hooking to pre_get_posts: function wpse276396_search_filter($query) { if ( !is_admin() && $query->is_main_query() ) { if ($query->is_search) { $text = urldecode( get_query_var(‘search_text’) ); $my_products = aws_search_byozan($text); … Read more

Pagination custom query

This is a local/global variable problem. It can be solved either by changing the pagination function to work with local variable, or by promoting the local variable into global scope. As you are using wp_reset_postdata(), i guess you want to keep the original query. Change the pagination function to accept arguments – if ( ! … Read more

Pagination shows 404 after a certain number of pages

The problem is that WordPress is executing the main query before your custom query (and the main query is based on the default post type only). You can intercept the main query, modify it, and then use it like so function add_blog_post_to_query( $query ) { if ( $query->is_home() && $query->is_main_query() ) { $query->set( ‘post_type’, array(‘post’, … Read more

Pagination with 5 posts per page

This is working for me on a single page using a template. Just be sure to set next_posts_link( ‘Older Entries »’, $the_query->max_num_pages );. // set the “paged” parameter (use ‘page’ if the query is on a static front page) $paged = ( get_query_var( ‘paged’ ) ) ? get_query_var( ‘paged’ ) : ‘1’; $args = array … Read more

Pagination not working with custom category template

As this is your main loop of your template, you should not be making a new loop, but modify the existing loop with pre_get_posts. This way you can be sure that all extra query parameters will be taken into account. An example of how you would do this: add_action( ‘pre_get_posts’, ‘wpse5477_pre_get_posts’ ); function wpse5477_pre_get_posts( $query … Read more

Change class=”page-numbers” in pagination

The paginate_links() function, located in wp-includes/general-template.php, doesn’t allow for certain parts of the HTML (such as the page-numbers class) to be customized. A simple string replacement will not work due to the way that the classes are generated, as highlighted in this excerpt of code from paginate_links(): $page_links[] = ‘<a class=”prev page-numbers” href=”‘ . esc_url( … Read more