I’m afraid you’re doing it a little bit wrong…
Here are the problems:
post_count
field contains the number of posts being displayed and not the offset.wp_count_posts
returns the number of posts globally, not in current query (so it will not be true for queries that have some filters).echo $post_count; . '-' . $post_count;
is not correct PHP code.
So how to do this?
All you need is the info from WP_Query:
<?php
$first_post = absint( $wp_query->get('paged') - 1 ) * $wp_query->get('posts_per_page') + 1;
$last_post = $first_post + $wp_query->post_count;
$all_posts = $wp_query->found_posts;
?>
<p class="small text-uppercase">Showing <?php echo $first_post . '-' . $last_post; ?> of <strong><?php echo $all_posts; ?> items</strong></p>
Related Posts:
- Alter query on edit.php
- Exclude posts from homepage having a specified tag
- Displaying the last post on static homepage
- Saving a post ID to use in a form elsewhere on website
- WordPress sorting posts by date and title using a dropdown
- Is there anyway I can call the year once?
- Automatically create a loop for post ID
- How to modify this function to exclude also the post belonging to a specific category?
- Handling error states with admin_post
- get_the_content if it contains multiple lines it results in SyntaxError
- Insert code when users come from an specific referer
- How to display related posts from parent category
- Make custom field meta not display if there is not data in it
- How to migrate the posts from an old custom legacy blog to a new WordPress website?
- Get_the_author doesn’t return author name
- Working with query_posts ( arrays and query strings)
- Hide wordpress field if data is empty in post!
- Can’t search posts using WP_QUERY inside AJAX Function
- How can I use wp_query to show all product data using just the products ID?
- Trying to add attribute to my posts’ featured image
- Using loop pagination on single.php
- How to set a min number of words for a blog post
- Loop through categories and display posts title under each dropdown
- WP_Query adds “(wp_posts.ID = ‘0’)” so no results are returned
- How to store post ID’s in cookie or session to display the same posts later
- Post + form + action + results on the same page
- Post repeating with infinite scroll
- Sort by page information by Ascending Numbers
- Display related posts without a plugin
- Count posts on multisite with blog id
- Making (and edit existing) posts with ID included
- Parsing Menu Items and Blog Posts
- Pagination on Custom Post
- $wpdb returns duplicate posts
- How to avoid duplicates when creating recent network posts
- How to show an entire post content and not also the excerpt?
- Update post title from external file?
- Why is a wp function used in current PHP namespace’s callback not resolved to global scope?
- Increment paged on WP_Query
- How to use mysql LIKE with wpdb?
- Add new post in existing categories using wp_insert_post
- How do I add more options to the post-new.php page?
- Modify main query before it run without pre_get_post
- .html end of URl affected to SEO?
- Get the id of all images in a post
- Do not duplicate posts with multiple categories in multiple loops
- Four posts per row [closed]
- Update if post with specific title exists
- Need help removing […] after excerpt
- WordPress Search
- posts_nav_link pulling in multiple post types
- How to break up php code to avoid echo
- Pagination in single.php
- Hot to check if new posts have been published since page load and notify online users?
- Edit and delete permissions pages and posts
- Advanced Query posts
- My Custom Post Type AJAX Query is Returning no posts – why?
- Post form – AJAX won’t upload featured image – Plugin development
- How to get post image caption by index
- Inside Array – “unidentified index” error with “prepare was called incorrectly” despite not calling the prepared statement with wordpress [closed]
- Check $post->ID against multiple values
- Don’t update modified post date when user add a product review or comment?
- Limit the number of characters/words in an excerpt for a related posts section
- Posts missing on author page
- How to allow users to save list of posts in wordpress?
- Need to show 7 posts from actual date
- Can I disable auto increment of WordPress Posts Database to utilize previously deleted records?
- Closing Comments conditionally in comments.php
- How to center all text body in single.php at once?
- Having trouble with customizing blog posts on the home page
- Related Posts: if there is no category use tags
- LinkedIn Share Post Button
- How do if all posts has this category ID then do this
- Get the total Author Favorited posts
- Get current_post in reverse order with pagination
- Getting error in sql query
- How do I generate formatted permalinks as specified in backend options?
- How do I get the featured post to share on Social Media and show on Individual Post pages?
- Insert div after every three posts in home.php [duplicate]
- PHP tag in post content makes wordpress go crazy
- Unable to get Post Category Name and URL
- Dynamically Create Posts Via XML File
- How to only fetch certain Tag ID’s
- Div Missing In Custom Loop Query
- Basic PHP question (displaying post title over thumbnail) [closed]
- insert thumbnail image from php script
- Post from front end form to post_meta
- media_handle_sideload() returned post_id being incremented
- Saving Post redirects to 404 page when php $_GET variable in post body
- How can I add WordPress Audio Player as featured audio in Audio Blog Posts?
- Trying to see if page is category or single and displaying title with appropriate heading tag
- Query specific posts per user selections from dropdown menus
- link to page_for_posts
- Pagination in category.php not functioning
- How to customize posts in WordPress by using HTML and CSS?
- foreach all the post
- Blog Posts not sorted and pagination not adjusted after filtering some category
- WooCommerce: write featured image dimensions to custom fields in product’
- transition_post_status hook, works – but not if the post is new
- How do I exclude the current post from the upcoming post query