Change
if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post();
to
if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post();
Why?
When you call $the_query = new WP_Query($query);
you’re storing the loop in a variable called $the_query
. $query
is an array of arguments that you’re passing to the new WP_Query()
function. $the_query
is a class and have_posts()
and the_post()
are methods which are basically functions specific to that WP_Query class.
Related Posts:
- How to fix pagination for custom loops?
- Pagination not working on home page
- WordPress category & taxonomy loop with pagination
- How do I prevent one of two multiple loops from repeating on a second page?
- Two custom loops, pagination, offset
- Previous and Next Post link doesn’t work
- Pagination adding extra posts only on page 2
- multiple loops with pagination on the same page
- Enable infinite scroll on single.php [closed]
- How to paginate this custom loop? [duplicate]
- Make a custom loop inside single.php with pagination
- Pagination gives extra page with no results
- Get Pagination (WP-PageNavi) not to work
- How to get an array of years from all of the search results, and use it to filter by year the paginated loop?
- Complex query and posts pagination
- Why only one post (and no pagination) on this variation of the loop?
- Calling & display certain product category loop and pagination on the homepage
- Make blog page show 10 on first page, 9 on every other page
- Pagination for multiple loops
- How to fix pagination for custom loops?
- How can I paginate this?
- Genesis multiple category custom loop 404s after first page
- How to fix pagination for custom loops?
- Pagination – works on local but not live dev!
- How do I paginate a get_posts() request inside another page loop (Paginating childpages)
- Pagination on Single Post
- How to get my loop to paginate?
- Distribute Gallery Images Every nth in Loop
- How to exclude or filter password protected posts when using next_post_link() previous_post_link
- How to append a query string to pagination?
- How do I get my loop.php to properly paginate?
- First archive page with a few posts
- Pagination broken after using 2 loops to show content
- Pagination on custom post type on front-page.php
- I have broke my pagination, same posts on all pages (index.php)
- Frontpage pagination by week
- How can this multiple loop have pagination as described?
- Display more than 10 posts on author.php file
- static page with multiple loops breaks post pagination
- Pagination for two loops
- Skip 5 latest post while paging?
- Why does my WP_Query pagination on a custom page.php only loads the homepage?
- How to insert content before pagination in loop?
- Pagination on a underscore custom theme
- WordPress multiple loops with default pagination
- How to fix pagination for custom loops?
- Style first 3 posts differently and use a 2nd loop to get rest of posts / offset and pagination broken
- Custom loop not working in singular.php, working in other pages
- Alternative layout the loop
- How to fix pagination for custom loops?
- Adding pagination to WP_Query [duplicate]
- How to fix pagination for custom loops?
- How to fix pagination for custom loops?
- Why is my pagination showing up?
- Displaying posts limit: can’t get pagination to display [duplicate]
- Paged homepage – requirements?
- Home page loop with pagination problem
- WooCommerce custom loop pagination on front page
- posts_nav_link() not working on index.php
- Custom Page Template and Category Exclusion
- repeating posts on 2nd page to posts
- Limitless amount of posts in custom archive page
- Same posts within a paginated page
- Multiple loop with pagination in same page
- Insert multiple custom components after x-number of posts
- How to split a loop into multiple columns
- wp_pagenavi() with custom wp_query()?
- Get post by page name or slug
- save_post + insert_post = infinite loop
- What is best way passing variables to theme templates and using them different places like widgets?
- Apply styling only to first page sticky posts
- Search results with custom loop don’t update when paged
- Woocommerce custom loop to show all the products [closed]
- Style first 3 posts differently with a container, then the rest of the posts [closed]
- Loop through all posts in a certain year
- Show the page title on blog page
- How can I make the loop not count special post formats towards the post count?
- Orderby my needs in foreach loop like by title or something?
- How to show posts with multiple tags on tag.php?
- Closing the loop…featured image variable based on post id
- How do you stop the rendering of the website to have something display on the front-end?
- add_action in the loop hooks
- Pagination for normal (standard) posts on a page with a custom loop?
- Offset Loop by 1 , Limit next loop to 1 (Most Recent) Post
- Database query and get_user_meta return incorrect data
- Need to while loop and display contents in the subfield of a group field given by ACF
- How to display a loop of custom post types in columns
- dispaly all hierarchical post types from a taxonomy
- WordPress Modal showing posts not working properly
- Query posts and display all dates in repeater field in chronological order
- Attachment Metadata inside of Loop
- Custom post type archive pagination with HTML5Blank theme?
- Insert/sticky multiple posts in multiple positions
- Stuck with conflicting loops on page template
- Pagination in custom query not working [duplicate]
- Show amount of posts created today above loop?
- How to create WordPress loop with combination of 4 and 2 columns twitter-bootstrap?
- How to add custom HTML markup and classes to the_content()?
- wp_mail sending only once inside foreach loop
- How to use orderby on meta_value when using Pods custom database table storage