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
- How to create a three column blog layout with a single query and with three different classes?
- Return only Count from a wp_query request?
- Conditional arguments for WP_Query and tax_query depending on if $somevar has a value
- query to find “parent” posts of CPT A while filtering “child” posts of CPT B
- Get Recent Posts by Date in Multisite
- next_posts_link not working for loop called with ajax
- author.php with ACF and CPTs
- Identify which loop you are hooking into; primary or secondary?
- WP Query: How to get posts from a specific author OR posts with a specific meta value
- Pagination shows 404 after a certain number of pages
- Get_post() with meta_key when compare is a date
- Match two posts in categories
- tax_query in WP_Query problem
- Display posts from Last 24 hours and order them based on most views
- Query with pre_get_posts to get pagination
- Pagination is not working using WP_Query
- Filter and list posts of a custom taxonomy
- Exclude first 5 posts of specific categories in the main loop
- How to show min 1 post from specific categories/tax WP_Query?
- Posts loop with pagination on a single post page
- Get custom posts with certain ids in a custom loop using a shortcode
- How WordPress attaches its Featured Images with posts?
- Tell wordpress to show a single page instead of an archive
- Have functions work outside the loop with 404 override
- how to merge a WPQuery array with a PHP array and use the Loop to Output the result
- how to make members list directory through wordpress post custom meta key.
- Loop Performance > JSON files vs. WP_Query vs. REST API
- Include current post into loop
- Is it safe to access the underlying mysqli object from \wpdb for custom queries?
- Post Thumbnail URL isn’t pulling into the background of div
- WP Query Compare cutting off last 2 dates
- How to combine two WP_Query objects?
- Loop 3 posts column wise and continue the loop into same columns
- Is it possible to retrieve posts depending on meta_key LIKE condition? [duplicate]
- WP_Query custom order and pagination
- Why is the value zero going in my custom database table?
- function wp() does not use meta_query?
- Widgets: Show Recent Posts Only if the Posts Have Both Categories X and Y
- get_children() Archive Template
- What’s the best way to make a blog page on WordPress?
- Populate select list with meta values from all posts of a Custom Post Type
- Exclude post from wp_query based on custom field boolean
- WordPress Meta Query Null Values Order
- WooCommerce WP_Query using tax_query returns no results (0 = 1)
- meta_query with relation = AND not working as expected when combining EQUALS with NOT EQUALS
- Using something else instead of using 9 wp_query
- make query more simplest and in one query
- Archive – Show Page Month Headers
- Order WP_Query results in order other than ASC or DESC
- Pagination in custom query not working [duplicate]
- $query_args for loop to only get posts from “current category”?
- Show number of posts AND number on current page (cannot make it work)