All query objects have a few built in vars that can help you display this.
Assuming your custom query object is $query
:
- The total number of posts across all pages is
$query->found_posts
- The total number of posts for the current page is
$query->post_count
- The current page number is
$query->query_vars['paged']
- The number of posts per page is
$query->query_vars['posts_per_page']
With that in mind, we can do something like this:
$pagenum = $query->query_vars['paged'] < 1 ? 1 : $query->query_vars['paged'];
$first = ( ( $pagenum - 1 ) * $query->query_vars['posts_per_page'] ) + 1;
$last = $first + $query->post_count - 1;
echo "Showing posts $first - $last of $query->found_posts";
EDIT – If you want to use the above with the main query, change all instances of $query
to $wp_query
Related Posts:
- How can I make the loop not count special post formats towards the post count?
- Apply an Incremental Counter in an Array Function
- How do I display an image before the first post of the loop when I’m using get_template_part?
- Problem with displaying HTML content after in_array [closed]
- Give each posts in a loop a number in sequence
- Count post views in loop
- Loop is crazy – one row displays wrong count of posts [closed]
- php loop error for count posts in category
- Custom Looping of WordPress Posts
- Link Button url count php and wordpress
- How to display Yoast SEO meta description in archive template for each post instead of the_excerpt()? [closed]
- How to get Author ID outside the loop
- remove tags from the_content
- the_title() shows title of the first post instead of the page title?
- Why do themes rely on “The Loop”?
- How to place comments_template(); outside the loop?
- Endless loop with wp_insert_post and wp_update_post
- Hook into the loop via a plugin, and output something after every X post?
- Two custom loops, pagination, offset
- What exactly defines a Main Loop and a Secondary Loop?
- Access to Media Library
- Getting two wp_link_pages output
- post loop causes wp_users and wp_usermeta DB queries for each users
- Alternate custom content in the loop
- Ajax loop refresh on click
- Run The Loop over array of post objects
- the_excerpt(), get_the_excerpt() and the_content() all killing “the Loop”
- Enable infinite scroll on single.php [closed]
- Is get_posts() more efficient than The Loop?
- loop through all posts memory error
- How to loop through ALL pages?
- Does get_template_part pull data once in a loop?
- Get titles of all posts with current tags except current post
- How to retrieve “sticky” post outside the “loop”?
- Using get_the_excerpt() Before The Loop
- How to make sure content doesn’t display if selection is empty
- code suddenly appearing from my tempate second loop
- Get post/page data outside the loop
- wp_query inside the_loop
- How to go about combining dropdowns / filter queries?
- woocommerce get_price_html not pulling in correct price
- Trouble Formatting DateTime
- Order archive results by post id in custom taxonomy template
- How to fix pagination for custom loops?
- pre_get_posts for two loops on same page
- How to display posts by vote count and if no value continue with latest posts with no votes?
- Sort results by groups of numbers and letters
- Modify the main loop to display current month / year
- Display post list with different styles
- Loop for sticky posts
- Get author_id in wordpress
- Single.php different behaviour from admin to non-admin
- Array ids post to function have_post
- Can’t access PHP array inside script localization from javascript
- ACF – add a group inside a repeater [closed]
- Trying to get property of non-object in shortocde
- Foreach displays from last to first
- value of metadata is null wrong use of if statement
- How to Loop with the final result formatted differently?
- Tags on page (not post) returns nothing – why? Improved clarified question!
- Separate First Post Loop
- add offset to archive page
- Category ID returns as ‘0’?
- make get_post work in the loop
- How to display 3 post per slide
- For Each +1 WordPress Loop
- Loops for cat links not looping for wordpress site
- Skip 5 latest post while paging?
- WordPress: query pages except remove one page
- get_post_meta printing empty fields, but it shouldn’t be
- Sort posts according to a numeric value entered with ACF
- Is it possible to set archive.php instead of index.php to display blog?
- How to read taxonomy in loop?
- wp_get_attachment_url not fetching URL?
- get the value for ALT is we check to see if an actual ALT value is set, if not we use the caption and if no caption is set we use the title
- Undefined index: page in loop load ajax content
- how to add 4 post in one carousel slide
- Exclude Posts Using Meta Query and User Meta
- Is “the loop” a template tag?
- Can I temporarily disable global $post?
- Shortcode for pulling specific Post Title outside loop when ID is passed in
- Show a list of user posts in the user admin page
- Alternative content between posts no repetition
- Deeply Nested Menu Loop with Twig using Timber [closed]
- WordPress with woocommerce custom query
- Page gets displayed in post field
- Active class for my flexslider in WordPress
- WordPress loop only displays 5 articles max?
- get_template_part() to render single page Theme
- Can’t see custom field after the Loop [closed]
- Showing related posts (custom post type) outside of the loop
- Same Loop on Multiple Pages
- Least Number of Loops to Create Custom Homepage?
- The Loop for my theme with static front page is not working
- WordPress loop: Display if posts exist
- strange parse error when including a loop template within another template
- Previous Posts Link and Next Posts Link Show All The Same Articles?
- Showing ads after posts in home page
- Undefined variable: woocommerce_loop [closed]
- Prevent duplicating specific column from database table