You do not need wp_reset_query() here use wp_reset_postdata() instead cause it’s a secondary query and you do not need to reset to the original main query.
Never use echo in shortcode, replace line :
echo "Nothing to show";
with :
$html_out = "Nothing to show";
To get what you want you may use :
global $wp_query;
$wp_query->current_post
It gives you the current position of the post in loop. Be careful, first post position is 0 not 1. So you may do the following :
if ( 0 === $wp_query->current_post ) {
/*some code*/
} else {
/* some code */
}
Related Posts:
- How to paginate wordpress [gallery] shortcode?
- What kind of object type is WP_Query?
- Last post ordered by publish date using WP_Query on front page
- Shortcode returns escaped HTML tags
- WP_Query in a shortcode
- ‘&’ causes an error in my shortcode when I list the content of the page
- Can certain (site-crashing) limitations on WP_Query in shortcode be overcome?
- How to retrieve current page WP_Query arguments?
- wp_query add arguments using array_push if variable met
- Category attribute not working in custom shortcode
- How to get all child pages in their parent page?
- Database Queries Optimization with new WP_Query
- Orderby is working with one query but not with other
- Shortcode for latest -not expired- posts
- Gallery shortcode numerical sorting
- How to filter a query by date in a shortcode?
- How should I approach changing the template & $query as part of a shortcode’s execution?
- Shortcode Not Working in Slider When Added To Post Title
- Shortcode for custom query not returning results when attributes are added
- How to Display Shortcode in the correct location, currently displaying before content after Page Title?
- WP_query only displays one of my custom post type entries
- Assign a minimum result count for WooCommerce query shortcodes?
- Using a Shortcode to List Posts from Multiple Categories
- embedding shortcodes in php template
- How to get specific string in explode array?
- Trouble passing attribute into shortcode function
- Woocommerce Shortcode which displays a table with product data
- WP Query by 4 different taxonomies
- create custom shortcode wp and put php code in
- How to display a post(by id) along with css in a page?
- Shortcode attributes causes 500 error after updating the page
- pages shortcode filtering by category
- WP_Query & shortcode : Return 3 articles from a category WordPress
- Query by Category and Custom Field – Shortcode
- How to take parameters from a function and make them editable as attributes in a shortcode
- Object of class WP_Query could not be converted to int inside shortcode
- How can I create another instance of my custom shortcode
- Get Current CPT taxonomy category in shortcode
- Custom shortcode not displaying categories and correct date
- return wp query results in a shortcode
- More efficient query to display posts in same sub-category?
- Having Trouble Running Query From Shortcode Using Tribe’s Events Plugin
- shortcode using multiple WP_Query’s with multiple category names not fully functional
- Shortcode does not display pagination [duplicate]
- How to write a query-function as a query-shortcode?
- shortcode with $atts with strange results
- WP_query shortcode inside acf Repeater breaks the repeater loop
- How to prevent WP query searching in executed shortcodes
- Find out total number of pages in global query on archive page?
- Resetting post data to previous loop in nested loops
- Is it possible to completely stop WP_Query retrieving posts?
- Pagination returns 404 after page 20
- Make a WP Query search match exactly the search term
- Make loop display posts by alphabetical order
- Displaying several specific pages using WP_Query()
- WP-CLI How to generate a list of posts with corresponding meta values
- Query to return maximum of one post per author
- Warning: urlencode() expects parameter 1 to be string, array given
- Group posts by custom field
- How to get the posts published in last two days using WP_Query?
- getting posts and number by specific meta value in multiple meta
- All sticky posts are returned in custom query
- Get attached media only
- Can not switch the queried post in pre_get_posts hook
- Pagination problem after WP_Query with tag filtering
- Custom Loop in Page Admin Causing Other Fields to Fail
- How to limit total number of posts in wp query loop?
- Get list of terms that have posts in another term
- Using Ajax to load more posts | Help me change the wording on my button to notify the user
- Adding an array from a query string to a WP meta_query
- WordPress add_rewrite_rule() cannot visit lower url levels
- Sort by price woocommerce by ID post_meta
- Retrieve posts using thumbnail id as meta key
- Why is WP_Query not displaying expected data?
- Filter post query to only show direct children of category
- has_excerpt() not working inside wp_query
- Apply query arguments after the nth post
- How to properly use AND / OR in custom search
- Get every post with value in meta key
- Using get_posts to get posts based on a checkbox value with Advanced Custom Fields
- Searching by title, content and custom taxonomy
- How to get posts by category and by choosing a taxonomy term?
- Paging + WP Query
- Getting the permalink to the latest post from a category
- Deleting terms from the WordPress wp terms table
- In a WP_Query can I force the results’ is_singular() to be set to false?
- Query pages created by deleted users
- Get posts that match defined arrays of tags
- WordPress live search and filter
- Why can my filter query SOME metadata but not other metadata?
- The query show user list orderby count published posts in last month
- How can I use WP_Query to sort ‘event’ custom post type by date?
- Sorting Posts by Taxonomy thats not within the query’s $args
- Website goes slow down after importing long database
- How to Query Updated Post in WordPress
- wordpress nested loop
- Query posts only shows 1
- First post outside of loop, homepage only?
- I want to place a post before all others from an ACF boleen field
- How to put posts with some taxonomy on top of others in `pre_get_posts`