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
- Post_count only shows the number of results per page
- WP_Query: query posts by ids from array?
- How to get order of posts?
- Combining two wordpress queries with pagination is not working
- pre_get_posts with get_posts
- Executing Queries in tag.php
- next_posts_link not working for loop called with ajax
- Why does pagination always break when used on any form of a home page?
- Identify which loop you are hooking into; primary or secondary?
- Trying to list out child pages with WP_Query
- Pagination is not working using WP_Query
- Intentionally exceed max_num_pages on main query without getting 404?
- Why execute the_post()?
- How to change posts order on Category and Tag archives?
- WP_Query on custom field and order results
- WP_Query condition affects posts_per_page count
- WordPress Blog Posts with Pagination inside a Page/Post
- WordPress | Date not always appear [duplicate]
- Is_single() conditional tag returns null in query
- Posts in loop all show the same author when there are many authors
- Multiple Rows in a using wp_query
- “paged” in WP_Query returns 0 posts
- If have posts a week old, display, else display a different loop
- Daily drip of posts – based on user ‘startData’ – ordered oldest to newest
- How to add tax_query to $args with concatenation
- How to split a post and intercalate elements from a loop
- How to create a widget like this?
- Notice thrown when creating numeric pagination on custom query
- Hiding carousel indicators if there’s only one post
- Does query_posts have an effect on get_the_category?
- Pagination problem by using WP_Query
- WP Query get only 1 post (sticky, not sticky etc)
- adding pagination to a foreach loop in wordpress
- Show custom content when loop or wp query reaches specific time?
- Loop through array of pages
- the_post_thumbnail and multiple WP_Query
- I have 3 categories, i want to display on a loop the last 3 of every category
- View related categories in order of posts
- Pagination in WP_Query?
- WP_query for posts with same post type AND same post category
- How to solve this script problem in theme directory?
- Show posts in category
- Both WP_Query and get_posts returning 1 post
- Pagination is not working on custom query inside a custom home page template
- Pagination not working in some author pages
- wp_query display posts based on day
- Sorting Posts Based On Meta Value Using AJAX
- Converting an existing query_posts to WP_Query
- Problem with WP_Query sort
- Get author meta data with no published posts in author.php?
- Help with showing text when something is entered in my search bar
- Custom query for certain post type OR another post type with a certain category