wp_reset_query(); resets the query to the original main query of the page.
Therefore, storing the query in another variable is redundant and unnecessary.
Updated code:
$args = array(
'cat' => 15,
'paged' => $paged
);
$custom_query = new WP_Query( $args );
while ($custom_query -> have_posts()) : $custom_query -> the_post();
endwhile;
my_pagination(); //call function
wp_reset_query(); //#3. reset query
Related Posts:
- Multiple WP_Query loops with Pagination
- Pagination returns 404 after page 20
- Pagination with WP_Query is buggy – working for some pages, but not the others
- Get the number of posts from the current page results
- Pagination with 5 posts per page
- Pagination/infinite scroll with WP_Query and multiple loops
- Pagination Not working on Home Page with 2 Query
- Display different number of posts from one category on the different pages
- Pagination not working Search posts
- Transient pagination not working properly
- Injecting content with $wp_query->current_post restarts from zero on paged pages. How to inject content after X posts, regardless of pagination?
- Woocommerce custom loop to show all the products [closed]
- How to bring specific post to front of wordpress loop?
- Pagination stops at page 6
- Paginated HTML Sitemap
- Multiple WP_Query loops with Pagination Not Working
- Posts loop with pagination on a single post page
- Create ONE callback for all page templates, post filter queries + paginated pages, triggering pagination via AJAX
- Pagination is broken and I need help fixing it
- Create A Loop With A Variable Number of Posts For Each Bootstrap Row?
- Five posts from a category in footer
- posts_per_page not working for first page of pagination
- How do I get my custom query to work with search results after the first page?
- How can I use the WordPress Loop and Pagination in multiple instances but different scenarios throughout my site?
- Stomping WP_Query in author archive to facilitate pagination with custom queries
- Second loop pagination changes URL, not content
- I am officially missing something about transient posts
- Query Not working as expected
- Paginate pages with dynamic query
- Function the_posts_pagination() not compatible with WP_Query arguments
- How can I have sticky posts while ALSO showing posts from a specific category using one WP_Query?
- Pagination inside the blog page not working
- Custom Query Pagination not working on static front page
- Paging works correctly on local version, but not live?
- Problem with custom WP_Query and underlying pagination/posts_per_page
- 2 Loops on one page – pagination of 2nd loop ignore array of excluded posts
- Pagination returns 404 after page 20
- custom query – offset to pagination
- Pagination not working with WP_QUERY
- No content found on page 2 of pagination with 1 post per page
- wp_query pagination links producing 404
- Loop being strainge
- Pagination in custom query not working [duplicate]
- Multiple loops on index page with sticky post and pagination
- Pagination problem with multiple loops on the same page
- WordPress Post Looping? [duplicate]
- Show number of posts AND number on current page (cannot make it work)
- Pagination only showed when no category is set in wp_query
- Multiple queries and pagination
- Custom WP_Query id
- Best choice for multiple loop in page?
- get_template_part causes 500 error
- WP Query – order posts by meta field first and then order the rest
- Append URL query to next post link in custom query
- How to display the featured image for each post?
- Assign custom parameter to each post in query
- How to provide meta_key array to wp_query?
- wp query error while paging the posts
- Wp_query with 2 meta keys and array of meta values
- Adding a html class based on post count
- Check for the main query from the template
- how to use pre_gets_posts to exclude one queried ID from homepage loop
- new WP_Query messes up pagination
- Trying to retrieve random post, getting a page
- Pagination is not working with custom query inside a homepage template
- Display single most recent post in category on every page of category archive
- Include latest author posts with pagination in single template?
- Posts in loop all show the same author when there are many authors
- Exclude recently updated post from custom WP_Query using multiple loops
- get_posts output always same post
- Pagination works in custom query loop but it doesn’t work in shortcode
- Multiple Rows in a using wp_query
- “paged” in WP_Query returns 0 posts
- How to use WP_Query() on single.php?
- Pagination on category.php and tag.php not working
- sort and display posts by custom field (wp-query and the loop))
- How to create custom query by keyword in post title?
- difference between querying database and using the loop
- If have posts a week old, display, else display a different loop
- WP_Query – Adding “offset” posts to the end of the loop
- How to make posts unqueryable/unpublish posts where ACF relationship field is an unpublished post? [closed]
- Conditional operator OR not working with custom fields
- Pagination on template page for custom query redirecting to index.php
- Getting blog pagination to work on page set as front page
- Loop increase in while loop not working
- Create a loop on my pages with new “WP_Query”
- Get posts that do not have the same tags as current
- posts archive page – closing WP_Query loop correctly [closed]
- Create a page template for “top rated posts” but show full content and not just a list
- has_excerpt() not working inside wp_query
- wp_query is showing posts from other categories
- Daily drip of posts – based on user ‘startData’ – ordered oldest to newest
- How to add tax_query to $args with concatenation
- Should I reset $wp_query?
- Meta query compare for ID’s greater than specific ID
- Exclude a Woocommerce product from WP_Query
- WP ForLoop to compare meta information of posts to determine what post to display
- Yoast primary category query modification
- AJAX Breaking Offset Argument In WP Query
- WP_QUERY wrong ammount of posts