What you are seeing is totally expected as you are trying to get the value of $current_post
outside the loop. Before and after the loop, the value of $current_post
will always be set to -1
.
To get the proper value, you need to check $current_post
inside the loop, the first post will be 0
and this will increase by one on every iteration of the loop.
For more info on creating the Post X of Y
thing, check out these site searches on this issue
Related Posts:
- Loop within a loop?
- WP_Comment_Query pagination, delving into the unknown
- Sort posts by category name and title
- Getting all user metadata from user
- ajax category filter
- Display posts the match taxonomy term linked from wp_list_categoies?
- How to get posts in different language from WPML Plugin [closed]
- Limit WP_Query to only X results (total, not per page)
- How to disable main query?
- Use post__in and post__not_in together?
- WP_Query on different site in a multisite setup
- how to retrieve specific product attribute value in an sql query?
- How to user WP_Query to lower the number of queries
- Compile two queries to one set of results?
- how do i combine keyword search and taxonomy in a WP_query $args array Worpresss [closed]
- Only display authors who have posts
- Sanitizing search data for use with WP_Query
- Update Loop with Form
- How to search by a post and a category name on wordpress at the same time?
- How to retrieve current page WP_Query arguments?
- How can I get an array of all IDs from the current queried object?
- Query Custom Post Type Order By Taxonomy Field
- WP_Query ajax loader detect end of posts
- How to get count of posts assigned to given category?
- WP_Query posts by distance based on LAT & LNG in Database
- Changing WP_Query params with url Query Var
- Wp redirect to url with ampersand string
- Get attachment by meta_key value
- Complex WP_Query order request: DESC by day, but then ASC by time
- How to detect if query is runned from widget?
- Change query based on post type while staying in loop
- Custom Pagination Layout for Elementor widget
- Multisite – Global CPT – advices?
- $WP_Query: How to display excerpt on first post only
- How to properly reset a nested WP_Query query
- Is there a reason why Pages are not publicly_queryable?
- Check return value of get_posts
- How Can I Change The Tax Query For The Main Loop For Taxonomy Archives?
- Exclude some authors from query
- WordPress Query String: get_posts(‘cat=5’) vs WP_Query( ‘cat=5’) vs URL: /site/?cat=5
- apply custom where to the default $wp_query
- wp_query serialised array
- Conditional operator OR not working with custom fields
- Multiple wordpress queries with nested output (odd – even)
- Using Transients
- Should I reset $wp_query?
- how to write wordpress query for multiple metakeys checking?
- Sorting search results with custom dropdown
- Posts query according to meta box date
- Using a Shortcode to List Posts from Multiple Categories
- How to display a list of posts in same child category as current post
- querying posts with a custom status
- problem with loop
- Display post meta conditionally based on it’s value
- How can i show pagenavi in my author.php?
- Randomly select one of last 3 posts
- Query multiple meta key values for template
- How do I get the content of a custom instance of WP_Query?
- Using WP_Query with multiple loops on one page in search.php
- Display upcoming events in the next 30 days by querying posts with timestamp in custom meta
- Order by post meta not working with pre_get_posts filter
- Searching not only by post name but also category
- WP_Query, Paginate by Custom Field
- ACF: How to query for a given value count of an array like field? (e.g.: How many rows has a `flexible_content` field?)
- is_user_logged_in not working from WP-API (wp-json)
- WordPress private post won’t display to other admins
- Only show tag with the same id as the post
- Search Exact on WordPress – Relevannsi Solution Not Working
- ACF: How can I publish values of ACF fields in a loop while using wp_query?
- Sort by price wpdb
- Posts per Page not working
- WP_Query random ordering not working since 5.4
- Show a message if there are no active posts in category
- Get authors list and sort them by recent posts
- How to get the latest post list (of the parent custom custom type)
- Problem with my loops
- next_posts_link not visible on first page
- Create global array to compare inside a query
- Pagination not working in custom loop WP_Query
- Multiple wpostmeta.meta_key
- Hi , i am trying to set the post for 24 hours and with it will be changed
- Own query vars are not displayed
- Saving custom fields for WP_Query to retrieve
- Show full category tree for a year with all post titles?
- Trying to use “Medium” featured image for custom post type on home page
- Modify query to exclude certain ids and certain parents and its corresponding children
- Filter posts/pages by user_role array
- WP_Query with meta_value_num and meta_query not paged correctly
- I need value of saved meta to display next to the post it is associated with
- Post Query not working after updating to 4.1
- Cannot order by in WP_Query
- Search Query that Includes Custom Table
- Pagination with WP_Query not working
- new WP_Query based on average values of meta fields
- Can’t seem to get an else statement correct? [closed]
- query_vars category_name only display one catgory out of multiple categories
- Incorrect posts displayed on category page
- How do I subquery with custom meta fields?
- Show number of posts AND number on current page (cannot make it work)
- Advanced Search – Is this possible?