You set $post_slug
outside the Loop, so the value never changes. You need to reset that inside the Loop so that it will be reset to each post in turn as the Loop progresses.
$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) {
while ( $the_query->have_posts() ) {
$the_query->the_post();
$post_slug = $post->post_name;
echo do_shortcode("[anything_slides cat=".$post_slug."]");
}
}
But there is really no need to set the variable at all. Just use $post->post_name
.
Related Posts:
- Query how many items to show in shortcode
- How to convert query sql to shortcode in wordpress?
- How to limit the number of posts that WP_Query gets?
- Stop WordPress automatically adding tags to post content
- Should we trust the post globals?
- Random sort within an already sorted query
- WordPress removing tags?
- how to get a different html for odd/even posts?
- How to know if get_posts() failed?
- Update all posts automatically when using post_meta
- Search & Remove Specific Shortcode From All Posts
- Using $wpdb to query posts with meta value containing current post_id
- Query posts from current year
- Shortcode Not displayed at the Right Place [duplicate]
- WordPress Number of Posts Not Changing With posts_per_page
- Automatically added brs and paragraphs?
- I have over 4000 posts, will querying some of them cause performance issues?
- Duplicate posts
- Looping through posts per category gives same posts for each category
- How to show posts rank based on custom field value
- How do I create Comma Separated list of attached image ids?
- How to add posts to wp_query result?
- Trying to put an array into ‘post__in’ => array() query not working
- Specific loop in Shortcode
- Order post by year DESC and month ASC
- How to add shortcode tags in single.php [closed]
- Should ‘setup_postdata()’ be reset with ‘wp_reset_postdata()’?
- How can I display a specific user’s first published post?
- Query All users that has post
- How To Add Perfect Apostrophe And Quotation Mark In WordPress Posts?
- Adding variable for post title so post template can include auto-generated link to view on external website.com/{post title}
- wp_enqueue_media() slows down my WP site
- How to create shortcode to show the 2 latest posts
- How can I get all posts data from within a paginated search result?
- Hide Post comments when displayed via WP_Query
- Search query – exact post title match
- Sorting posts alphabetical that have single digits
- Query posts from different categories in multisite
- Check if post exists
- posts_per_page doesnt work
- Remove Shortcode […] from Blog Preview
- Sorting posts according to view counts not working
- Display page content AFTER a loop of posts
- Only display posts after current date
- Get posts by multiple ID’s (query)
- How to start with post number x?
- Exclude posts with empty post_content in wp_query
- Only display a certain number of posts, dependent on how many posts there are available in a query
- Display a post by ID attribute with shortcode
- UberMenu list current user’s posts as menu items
- Improving WP_Query for performance when random posts are ordered
- Should $found_posts be returned as string in ‘found_posts’ filter hook?
- Duplicating Table of Contents for Paginated Post
- Get posts by name and taxonomy term
- WP_Query Authors OR Categories
- Get Posts that are in the current month or later
- Sticky post appears twice
- How Can I Query a Specific Page From a MultiPage paginated Post
- Get Meta Key Value While Saving Post
- Most liked page not displaying posts
- How to get rid of shortcodes in post content once and for all
- get_the_content(“more…”) returns full text
- Query get post,how to add comment box
- Is there a straight-forward way to iterate over all shortcodes in a post?
- How can i display gallery shortcode output under Post text
- How to display Common posts from specific Tag & Category with Shortcode
- filter RSS feed in URL
- WordPress custom Query for Posts in Category display posts multiple times
- What’s the best way to render Visual Composer in posts, not pages?
- get query() without post content?
- display-posts shortcode attributes have no effect
- Shortcode and whitespace formatting problem
- How can I setup a relationship using categories in WordPress?
- Exclude the first ‘n’ number of posts of a tag from home page?
- posts_per_page option limits the number of Gallery items
- How i can limit period of post publication?
- Shortcode to display the latest news article within a page
- How to setup a query to output posts by groups of five?
- Shortcodes on my website stops working after theme update [closed]
- Exclude current custom post on single post
- Dynamically switch template on click
- How to get posts and comments amount per hour, per year and per month?
- Get all custom post types excepted some…
- How to get ID of the page included with get_page()?
- Get all comments of author’s posts
- First x post with another template then the others
- Why Query is returning empty array?
- Delete all drafts?
- How to get a post’s details by shortcode?
- Wrap every month posts in div
- Inner join overrides Advanced Custom Fields plugin’s get_field [closed]
- meta_value timestamp older than now
- Counter is skipping post when I still want it visible [closed]
- Do not show children of a category
- post__in not working with pre_get_posts, but post__not_in does work
- Can’t get full post title if there a spaces in title
- How to get all post_parents of a post?
- Query for first 3 posts to change the look and feel
- Why posts array is empty?
- Query posts and filter at query time by value of custom meta