The main query has a loop counter build in which you can access via $wp_query->current_post
. This counter starts at zero, so you would most probably add one to that count, something like $wp_query->current_post + 1
Also, you don’t need to separately count posts, that is also an already build in function which you can access with $wp_query->found_posts
. This will return the total amount of posts in the query
EDIT
wp_reset_postdata()
should be used after the loop, not inside, so you should move wp_reset_postdata()
to after endwhile
Related Posts:
- Display all posts in a custom post type, grouped by a custom taxonomy
- Should unaltered default loop/query return a list of custom posts belonging to a custom taxonomy?
- Query for posts in 2 taxonomies
- Separate Posts and Custom Post Type in Custom Taxonomy archive template
- wp_query to find posts by year and month
- Custom Post Type Loop within Shortcode
- Filter by custom taxonomy slug on a custom post type
- Display CPT posts based on specific taxonomy
- Custom loop with multiple taxonomy queries
- What’s the WP way to load remaining custom posts?
- display posts of custom post type with custom taxonomy
- List all Custom Post Type posts excluding certain Taxnomy term
- Cant’ Display Custom Post Type Title Base on Tax Terms
- Loop for custom-post-type comparing taxonomy terms for “related” posts?
- Multiple custom post type queries causing wrong post types to be grabbed in taxonomy + single templates?
- Query for specific taxonomy that executes a particular loop depending on volume of posts?
- What is the most efficient way to execute recursive complex queries?
- Loop with Custom Post Type and Taxonomies
- Catergory args causing loop not to show
- display custom post type from register taxonomy
- Complex Custom Loop with Includes
- Exclude a category from WP_Query
- query multiple taxonomies
- WP_Query to loop a Custom Field, Custom Post Types do not show
- Sorting a list of posts displayed under a list of associated terms (which should be sorted without initial articles)
- Sort the main query in subcategories/terms?
- List all posts in Custom Post Type but group dynamically by Custom Taxonomies
- How to show posts from multiple post types in a single loop? And display them separately on the same template
- Custom Taxonomy List links being re-written
- How to display the rest of categories on Portfolio filterable
- Want to filter only parent post in admin area
- Custom Taxonomy and tax_query Issue?
- Query Custom Post by Category
- ‘category__and’ for custom taxonomy?
- WP_Query and using a variable for ‘cat’=> in the args array = WP Bug?
- Custom post query by taxonomy
- Show Post Count of a Category
- Lists Posts from CPT that match the Title of the Page
- Group custom posts by custom taxonomy names
- How can i skip same post from taxonomy term?
- WP_Query orderby modified to include custom meta changes
- get_attached_media() on author page not working
- Wrong request query on cpt and tax
- Pagination for Custom Taxonomy Page [duplicate]
- Search / Filter posts on Title/Content OR Tags
- Custom post type multiple loop by taxonomy term
- List custom taxonomy specific to one custom post type
- Advanced search form with filters for custom taxonomies
- get_the_title() is returning results from previous loop
- WP the_posts() on single-cars.php get category link
- tax_query not working in template
- How can I group posts by months and years?
- Multiple Custom Post Type queries, how to DRY it up
- Main query not querying any posts in custom taxonomy template
- Creating two loops based on different logic
- How to show all taxonomies within custom post type loop
- Trying to add a class to post links
- Query Posts that have Custom Taxonomy
- Display post from custom post type
- Foreach loop returning more than one item when querying taxonomy
- Compare Two Custom Post Types Using The Same Custom Taxonomy
- Loop and add Specific Categories and Products Images
- Sorting the Loop by Taxonomy Value
- How can I loop at a Specific Taxonomy from a custom post type?
- Custom archive page for custom taxonomy and pagination issue
- Ordering by meta value not working
- posts_per_page in custom WP_Query does not override “Reading” settings?
- Custom post type paging return home page
- SEARCH QUERIES – REVERSE OUTPUT
- WP_Query to display number of custom post type filtered (order by) taxonomy
- post_type incorrect for custom post type
- Live search by custom tag
- Query a custom taxonomy in a function to create an csv file
- Multiple Custom Post Type in Taxonomy Archive Causing White Screen
- Adding a Section for Visitors
- Why is my loop not populating the page with my custom taxonomy terms from my custom post type?
- Show parent category and subcategory once in while loop
- Mix Facebook and Twitter feed into custom posts
- Loop to display parent categories in custom taxonomy
- Display all Custom taxonomy terms and their relevant custom posts
- Strange behavior on WP_query
- CPT Efficient way to display posts from different categories with custom query
- How To Loop Through list with Custom Post Types
- Query Pulling the same post twice
- Custom taxonomy page template
- Get posts associated with custom taxonomy alternate way
- Custom Post Type + Category archive
- display news with pictures 3 small and one large (loop)
- tax_query showing no results
- Values inside a custom field to determine which category posts to display
- WP Query WordPress Post Type with the same Taxonomy name
- How to retrieve taxonomy terms of the current custom post?
- Custom post-type’s pagination not working in category.php
- Listing all custom post types using a specific term on the said term’s template page, in groups
- How to Get The Taxonomy Term in Custom Post Type Loop Inside a Wp Query
- How do I correctly query posts from a post ID?
- Get all active posts that are tied to a custom taxonomy for a custom post type
- How to insert a post from a different post type after every nth post
- Sort ACF by custom taxonomy
- Dynamically count the number of custom post types associated to a custom taxonomy