But all of them get obtained from the database.
The problem is that you’re ignoring half of them. Or rather merging two of them and displaying as one.
Let’s take a look at your code:
while ( $query->have_posts() ) {
$query->the_post(); // <- here you call the_post() first time
$output.='<div class="entry filter_product">';
// and in the next line you call the_post second time
$output.=get_the_post_thumbnail($query->the_post()->ID,'medium');
$output.='<h3 class="title">'.get_the_title().'</h3>';
$output.='</div>';
}
Every time you call the_post method, you tell the loop to go to the next post. So if you call the_post twice in one loop, then you’ll be skipping by two posts, not by one.
You should change this line:
$output.=get_the_post_thumbnail($query->the_post()->ID,'medium');
To this:
$output.=get_the_post_thumbnail(get_the_ID(),'medium');
Related Posts:
- Why is this coming back as null? Thats wrong. There is one post
- Two loops on archive page
- Check if loop has any categories?
- How to make search for posts using get method?
- Wp_query with 2 meta keys and array of meta values
- Writing less unnecessary code with WordPress
- How to separate two columns from one content on a page template?
- WooCommerce | AJAX | Product Pagination | Help me implement Ajax Pagination
- Second WP_Query loop shows data from main query
- active link for most recent post on vertical tabs
- Get author meta data with no published posts in author.php?
- Can I force WP_Query to return no results?
- Multiple WP_Query loops with Pagination
- WP_Query vs get_posts
- WP_Query and next_posts_link
- Too slow when using both ‘tax_query’ and ‘meta_query’ both in WP_Query
- Get array of posts from the current archive page loop
- How-to exclude terms from the main query the most performant way?
- Pagination with WP_Query is buggy – working for some pages, but not the others
- How can I save an array from a random post sequence for later use?
- In loop: posts have thumbnail AND other variables
- How to order category.php loop by ‘meta_value’?
- Add inline HTML to posts published within last 24hrs
- How can I display recent posts from a particular category in my header?
- Move posts to top of WP_Query if in certain Taxonomy?
- Ajax Infinite Scroll In Custom WP_Query Loop Not Working
- Display different number of posts from one category on the different pages
- Pagination not working Search posts
- Injecting content with $wp_query->current_post restarts from zero on paged pages. How to inject content after X posts, regardless of pagination?
- Can certain (site-crashing) limitations on WP_Query in shortcode be overcome?
- Implementing an OR statement to wordpress wp_query
- Get List of all the Authors
- Create ONE callback for all page templates, post filter queries + paginated pages, triggering pagination via AJAX
- WP_Query arguments to fetch custom post type posts which are in certain category?
- WP_Query loop within WP_Query loop
- Refine search results using WP_Query
- How to pass many ids in post__in?
- How to use WP_Query to display many posts?
- How to show subcategories using loop?
- Sub-loop / nested loops Best Practices
- Five posts from a category in footer
- Which method is faster to get a single post?
- Show Sticky Post at the top but do not show again in the loop?
- Any number in meta key (wp query)
- How do I run through a WordPress loop called from a filter function?
- How do I get the title of a category in a custom loop?
- Order by empty custom field
- Out Of memory issue on post per page parameter
- WordPress query with items from more than one selfdefined taxonomy as `term` argument
- Multiple filter conditions for WP_Query
- Get all fields inlcuding “ACF” (Advanced Custom Fields) columns in wp_query
- New WP_Query loop in admin causes problems
- Need to convert string of term ids into comma separated integers for use in an arguments array
- Change query from cat id to slug or name?
- How do I get my custom query to work with search results after the first page?
- Using Wp_Query without the loop?
- What happens to the default query when I use WP_Query?
- Custom WP_Query id
- Assign custom parameter to each post in query
- Custom WP_Query doesn’t display all posts
- Exclude recently updated post from custom WP_Query using multiple loops
- How can I prevent posts with no title showing up in my query?
- difference between querying database and using the loop
- posts archive page – closing WP_Query loop correctly [closed]
- Continue or break the while loop
- Loop posts based on permalink term
- Check if a post has term inside loop
- How to Order By Two Custom Fields?
- Display specific page (that is child) content on parent page
- Does putting queries within loops cause an issue on WordPress?
- Function using get_posts() with tax_query not working when called from functions.php
- How to create Page templates for showing Blog posts in different layouts?
- WP_Query not getting all posts, just tagged posts
- Paginate pages with dynamic query
- WP_Query loop doen’t work with my custom taxonomy
- Search.php gets metadata from first post
- How to make the ‘request’ filter work?
- show most viewed post
- How do I stop the same post showing multiple times in a archive?
- how to get custom attachment url?
- How can I use WP_Query to sort ‘event’ custom post type by date?
- WP_Query & Duplicate entries
- Get posts by similar names and categories
- Calling a function with WP_Query only ever brings the first result
- query_posts() doesn’t seem to be called in my page
- Pagination returns 404 after page 20
- Ordering Posts by parent category, name ascending
- WP_Query a custom field value bringing back 0 results
- Set Transient on CPT
- Create multiple sections for all categories and then queries all the posts for each of those categories
- Next / previous posts link doesn’t show up with Posts 2 Posts
- Creating array to compare custom field values
- Carousel Loop only duplicating
- How to show featured post first, then separate loop for other posts
- Show linked products using wp query and woocommerce
- Standard Loop – wp_query
- Custom Wp_query loop takes very long
- How to display posts from a specific term first then another posts from another terms using tax_query
- Show number of posts AND number on current page (cannot make it work)
- WP_query shortcode inside acf Repeater breaks the repeater loop