One issue at least: you’ll want to close the loop before outputting your pagination links, or else they’ll be output on every iteration of the loop. But you’ve got paginate_links()
before endwhile;
.
Try this arrangement instead:
// open loop
if ( have_posts() ) : while ( have_posts() ) : the_post();
// Loop markup
// close loop
endwhile; endif;
// pagination here
paginate_links( $args );
For a custom query loop, you’ll want to handle the query accordingly:
// custom loop query
$custom = new WP_Query( $args );
// Pagination fix
$original_query = $wp_query;
$wp_query = NULL;
$wp_query = $custom;
// open loop
if ( $custom->have_posts() ) : while ( $custom->have_posts() ) : $custom->the_post();
// Loop markup
// close loop
endwhile; endif;
// pagination here
paginate_links( $args );
// reset query
wp_reset_query();
Related Posts:
- Pagination with custom SQL query
- Pagination on a WP_query not showing navigation links
- Different ‘posts_per_page’ setting for first, and rest of the paginated pages?
- How to paginate wordpress [gallery] shortcode?
- paginate_links ignore my format
- Custom WP_Query order by post_meta and (author) user_meta
- How to paginate attachments in a secondary query as gallery?
- Query causing load because of SQL_CALC_FOUND_ROWS post counting?
- Pagination with 5 posts per page
- Pagination not working for Custom search form & custom result template
- How to adjust found_posts so that it accounts for offset and pagination
- pagination doesn’t show up for custom post type
- Pagination causes error 404 when used with front-page.php
- Paginated pages are showing correct content but pagination links are not
- Pagination wont work with search results template [duplicate]
- Pagination Not working on Home Page with 2 Query
- Best Practice For Querying Grandchildren?
- Pagination not working for category posts
- Two queries on the same page with pagination
- Is there a PHP function that can match anything after the given URL, so my IF statement will work in each instance?
- Add custom search results to main WP search [duplicate]
- Pagination for custom query on single.php
- Pagination doesn’t work in custom page template [duplicate]
- WP_Query pagination not working in admin area
- WP_QUERY loop, offset in the arguments and the paginate_links – can these work together?
- Too many posts cause slow load when paginating
- How to output different posts per page?
- Multiple WP_Query loops with Pagination Not Working
- Custom pagination with WP_Query generating 404 error
- Pagination working everywhere but the index page
- Offset Page Loops and Pagination
- How to set pagination to work with ‘/page/’?
- Get pagination working for custom loops within page templates
- WP_Query Pagination on multiple-loop page breaks WP or doesn’t show up
- pagination with ‘no_found_rows’ => true,
- how to handle multiple ajax wordpress queries?
- Custom Pagination Layout for Elementor widget
- Pagination links missing for first link (1) and previous button? How to get pagination links to work?
- How to return a 404 when custom query matches nothing?
- Pretty urls for custom pagination
- Multisite pagination issue by multi query archive 404
- Custom post type archive pagination query issue
- paged variable not working for category/custom post archive
- WordPress Blog Posts with Pagination inside a Page/Post
- Append URL query to next post link in custom query
- new WP_Query messes up pagination
- Pagination is not working with custom query inside a homepage template
- Display single most recent post in category on every page of category archive
- Pagination works in custom query loop but it doesn’t work in shortcode
- “paged” in WP_Query returns 0 posts
- Notice thrown when creating numeric pagination on custom query
- Content not displaying on paginated page
- Second loop pagination changes URL, not content
- I am officially missing something about transient posts
- Custom Homepage Pagination using WP_Query
- Adding pagination to sub-wp_query within a singular post page
- How to filter a static post page with ajax and $wp_query
- Pagination problem by using WP_Query
- WP_Query and pagination AGAIN?
- WP_Query, Paginate by Custom Field
- Reciving Error 404 blog/page/2/
- adding pagination to a foreach loop in wordpress
- wordpress pagination wont render on custom page template even though its right under the loop like the documentation says so
- How can I have sticky posts while ALSO showing posts from a specific category using one WP_Query?
- Pagination repeating posts on search results
- Pagination for Category does not work
- Pagination on archive.php not working?
- Pagination not working in custom loop WP_Query
- pagination functions are not working
- WordPress pagination not returning posts on second page
- Problem with custom WP_Query and underlying pagination/posts_per_page
- Pagination in WP_Query?
- 2 Loops on one page – pagination of 2nd loop ignore array of excluded posts
- 3 wp_query on one page with pagination for last query
- Custom pagination (Title, date and teaser)
- custom query – offset to pagination
- Add pagination to table generated by wp_query
- Pagination is not working on custom query inside a custom home page template
- Pagination in custom query in a category page
- Pagination not working in some author pages
- How to add archives (with pagination) to page template?
- No content found on page 2 of pagination with 1 post per page
- What is wrong with this pagination code?
- Can’t get pagination to work with this WP_Query loop
- Pagination in custom loop [duplicate]
- Why won’t my paged wp_query work? [duplicate]
- WP_Query breaks pagination
- Pagination doesn’t work for home page custom post type query
- Loop issues when creating custom query for media uploader
- Query multiple taxonomies with pagination
- Pagination in WP query with transient API
- paginate_links() with Custom Taxonomy
- Multiple loops on index page with sticky post and pagination
- Pagination problem with multiple loops on the same page
- Pagination not working in secondary query
- WP Paginate not working properly
- Pagenavi with archive page
- Search results stuck on page 1
- Pagination only showed when no category is set in wp_query
- taxonomy-{term}.php terms pagination returning 404 after a certain page