-
If you are inside the loop, you don’t need to access global $post, you already have $post variable accessible in your local scope, and this variable holds the data from current loop iteration.
-
If you are outside the loop, then you need to access global $post first, and it will hold whatever data it was left with (the first post in the loop usually).
As I understand, you’re trying to output the slug of the current post in your custom loop (not main). In this case, just use $post->post_name
;
Related Posts:
- Get post by page name or slug
- Exclude category by slug for for each loop
- How to show posts with multiple tags on tag.php?
- Why doesn’t ‘continue’ work in page?
- WordPress Tags in class
- Jquery Slider for profile template
- Get excerpt using get_the_excerpt outside a loop
- Retrieve each widget separately from a sidebar
- Should I use loop in the single.php file?
- wp_list_categories: get latest featured_image of category
- Where should I use post_class()?
- get_the_foo() in the loop – does it perform another query?
- Exclude filter on front page
- category__not_in — anyway to use category name instead of id?
- Is it possible to display previous post revision?
- Check if date of post is yesterday
- Exclude first 2 posts with meta_key from loop
- Fix inefficient loop breaks post.php on form submit
- Make a custom loop inside single.php with pagination
- Why do I get `Call to a member function have_posts() on a non-object `? [closed]
- Help with Changing loop.php?
- Get Pagination (WP-PageNavi) not to work
- Filtering The Loop For Single Page and Blog Page
- the_content() seems to block my ACF-code
- Pulling current post/page data into header.php
- Loop and Page template : my WP_query don’t take args
- How to split a loop into two columns
- Category Ajax call
- Transient loop issue
- popular post weekly and monthly
- WordPress Loop inside Loop?
- Get single post from tags array
- WordPress loop: exclude if it is the latest post
- Apply an Incremental Counter in an Array Function
- Get all posts including sticky ones with get_posts(),setup_postdata(), and foreach loop?
- Latest Post Styled Different Than other Posts
- ACF custom field in [closed]
- Split wordpress loop to multiple layouts
- WordPress: Loop Help
- Woocommerce: How to display product price [closed]
- Update status of all posts in a category
- Enabling users to control custom loop’s query
- Loop counter style
- Can I add generic numbering HTML classes to items as a loop runs?
- Add “showing posts x to x of y” in custom post type paginated loop
- Custom Post Type on Homepage – Studiopress Genesis Framework
- New loop vs widget
- Display a single category in blog section
- Query Nopaging action not having effect
- Yoast taking over my WordPress title tag [closed]
- Pagination broken after using 2 loops to show content
- get_template_part() Not Working in Loop
- Query posts only with actual text content (not including shortcode or images)
- CPT while loop not working
- Problem with Front-Page.php loading recent posts
- Default featured image set as background image [closed]
- Breaking up the results of a loop
- Where to add offset?
- How to synchronize The Loop with the max post per page?
- How to add a byline to all the pages?
- How do i create a list-posts-page?
- Exclude posts based on an array
- Displaying member join date on page
- Ascending order has strange effects on wordpress loop
- Is file_exists() compatible with timthumb.php? [closed]
- List ALL posts by author on author archive
- Using is_page_template inside loop
- Archive: Lists itself
- How to show the last article in a different way in my blog?
- Can’t limit posts_per_page in loop
- Slug is changing when I use WP_Query in a metabox of a post
- How to fix pagination for custom loops?
- Check to see if a field is within an array in twig
- Custom loop not working in singular.php, working in other pages
- Strange problem with wp_get_attachment_image_src database (db) query count
- How to include posts from one category, into a separate category of posts?
- how do i make this loop work
- Archive sorted by month – separate
- Making a specific page wordpress compatable that is not index
- One page loop issue with posts
- Humanmade | Custom meta box class: How to display a repeatable meta box group?
- Can’t print out returned value
- change the_content images for different sizes (Desktop, tablet, mobile)?
- Building theme so user can change header image [closed]
- Get query result before posts are displayed?
- WordPress Group By Problem
- Home page loop with pagination problem
- WooCommerce custom loop pagination on front page
- Eliminate duplicates in a foreach loop [closed]
- Tag custom loop show posts
- While loop inside another while loop
- get_page() unlike Loop returns the post content without html tags. How can I fix this?
- Problem with ms-thumb-frame-selected class in Master Slider
- I want the first post on my home page to be lengthier than the rest (example included)
- Loop with Custom Post Type Taxonomies and Interstitial Code
- Question about custom plugin
- loop mix my child-category and parent-category
- How can you make it so the comment box shows on some pages or posts but not all?
- Insert multiple custom components after x-number of posts
- Hook in the loop after the first post