Use the property current_post
of a WP_Query
object – it’ll be zero for the first post:
if ( $wp_query->current_post === 0 )
// First post in main loop
if ( $get_videos->current_post === 0 )
// First video in current videos loop
Related Posts:
- Why does apply_filters behave different inside and outside a loop?
- Order Posts By Youtube Views
- When to use WP_query(), query_posts() and pre_get_posts
- How to get an array of post data from wp_query result?
- How to only display posts whose meta_value field is not empty?
- How to print the excuted sql right after its execution
- Is it possible to completely stop WP_Query retrieving posts?
- WP query taxonomy input differs to output?
- How to add taxonomy filter on the query fly?
- Pagination returns 404 after page 20
- Make a WP Query search match exactly the search term
- WP_Query min and max values
- post_type is ignored by WP_Query when ‘tag’ argument is included
- How to query posts of standard post format. For real
- Orderby menu_order doesn’t work
- WP_Query by Category Name
- Warning: urlencode() expects parameter 1 to be string, array given
- WP_Query OR clause for tax_query and keywords
- All sticky posts are returned in custom query
- Transient pagination not working properly
- query posts in functions.php and update a field
- get_posts() seemingly ignoring post_type
- If orderby parameter using pre_get_posts is the same for multiple posts what fallback does the query use?
- Can not switch the queried post in pre_get_posts hook
- Which filter/action hook gets triggered after a query has been performed?
- Why use JSON API to display recent posts?
- Why query_vars get altered in WP_Query Object?
- pre_get_posts filter meta_query without conflicting existing meta_query
- Minimising Database Queries when using Advanced Custom Fields
- Get list of terms that have posts in another term
- Get data of all posts of a query before pagination
- WP Pagination on Posts Search Results Page resulting from AJAX WP Query
- How to avoid wp_query returning the same post I’m on in results?
- Custom query for sidebar isn’t returning results
- How to vary post loop results layout and resume?
- Adding an array from a query string to a WP meta_query
- WordPress Loop and $post
- How can I create ‘future’ and ‘past’ parameter for restAPI by filtering the CPT custom date field by greater than / less than current datetime?
- WP_Query tax query part of slug
- Query posts without meta preload
- How to implement a new row_count method in WordPress?
- Applying posts_clauses filter to specific queries only
- Some doubts about how the main query and the custom query works in this custom theme?
- How to do a wp_query with two acf-fields, sorting on one of them
- Using Advanced Custom Field for file upload, how do I load the file url
- Retrieve posts using thumbnail id as meta key
- Shortcode for latest -not expired- posts
- meta_compare not comparing whole integer
- WP_Query – Object manipulation vs WordPress functions
- Only display post if published in last 24 hours?
- Transients with dynamic WP_Query
- How to remove the most recent post from $the_query
- WP_Query loop else statement not executing
- Modify Search Query if original Query gave no results
- How to cache wp_query with pagination using transients?
- Problem with WP_query
- Selecting posts with a given meta value for a meta key
- pre_get_posts – editing query, tax_query
- Check if a post has term inside loop
- Display all posts in a custom post type, grouped by a custom taxonomy. How to sort the posts alphabetically and the terms by ID?
- How do I add a relation parameter to my filter query?
- Hacking ‘posts_per_page’ in WP_Query
- How to get posts by category and by choosing a taxonomy term?
- Post archive for certain post format
- Issue with data array format
- Add AJAX “Load more” on custom query block
- Why my query is not “Main_query”?
- Filter sub-category from checkbox form
- Meta Box WP_Query array for showing items with a certain relationship
- Multi-layered WP_Query
- `offset` WP_Query argument dont work via `pre_get_posts`
- Function the_posts_pagination() not compatible with WP_Query arguments
- How to add a “base” filter for all posts visible to visitors on the site?
- Pagination of custom page with custom fields query
- WP_Query custom post with by general tags
- WP_Query() not filtering posts for category
- WP_User_Query Orderby Not Working
- add action for wordpress query at a specific position
- WordPress post_status and meta_query
- How to query wordpress with array of meta_values?
- How to pass a php variable to js within a template?
- Custom query: post__in parameter causes query to be empty
- Custom query return
- WP_Query: Meta_Query with serialized value (or a workaround)
- Query All Attachments and Order by Parent Publish Date
- WP_Query using meta_query with LIKE doesn’t return what it should
- Filter custom post type by custom taxomony
- Query post Pagination Problem
- An archive page without post format (just standard post)
- How to organize a WP_Query’s list of posts by category and display category title?
- How to Query Updated Post in WordPress
- Pull Instagram images into an existing loop?
- Query_vars not working for me
- Pagination showing same posts despite changing page
- Query custom post types by meta field in a term from custom taxonomy
- Filtering product search results using tags
- Refresh wp_query with no changes
- SQL query into to WP query
- WordPress WP_Query Search (‘s’) With Multiple Search Terms
- Search results stuck on page 1