That’s expected, this code gets the date of the current post:
$post_date = get_the_time( 'd-m-y', $post->ID );
But you’re not inside the post loop yet, so the current post is the page you’re on. the_post
is what sets the current post, so you need to call this inside the loop, not outside.
There are some other issues:
- Use an editor that auto-indents code, especially if you’re sharing it, indentation avoids an entire group of bugs
echo esc_url( get_the_permalink( $post_id ) );
refers to$post_id
which is never defined, it’s just pulled out of thin air- There is no
else
case, if no posts are found it’ll just be blank
Related Posts:
- Function to execute when a post is moved to trash .
- Set tags for a post – without tag creation
- Limit on the max number of words per post?
- How can I safely increase the character limit for post passwords?
- Fatal error: Call to undefined function post_exists()
- Replace image attributes for lazyload plugin (data-src)
- How to create WP Editor using javascript
- WP_Query to work with custom view
- Edit a post from frontend. post_tags get saved, but not separated
- Get the user type of an author
- Related posts display randomly by tag
- Edit meta data does’t work with custom sql
- Restrict access to the Trash folder in Posts
- Post custom permalink results in 404 for archive page
- Check if Currently on Static Posts Page
- get next next post in single.php
- Unable to modify(update) posts – Page not found
- How do I get the slug of a custom taxonomy category of a post?
- Featured Posts for Category Pages
- Fatal error post.php help :(
- Cannot Update A Post, 404 Error
- Hiding posts in a list from specified categories
- Disable Post/Page comment emails for creators
- Changing html lang depending on author
- How many post WordPress can handle?
- Create an article from another Java application
- WP_Query do not load specifed number of post
- Manually removing revision post types
- Display most recent post in full, excerpts of older posts
- Buddypress activity id
- Modify WP_Post before processing
- How to rename “Publish” metabox title in post screen
- Tags to Post-ID mysql query. Tag Search
- Specifying # of Posts per page using inline post plugin (:
- Display post from current category and same tag?
- How to display WordPress archive into three columns [closed]
- Applying $posts_clauses filter to specific queries only
- How to get post bulk edit action trigger and get edited post ids?
- Paginated Posts – Social Media Buttons Share First Page URL
- edit_form_after_editor only in post edit pages
- Is there a straight-forward way to iterate over all shortcodes in a post?
- Using custom post template
- Display post option on frontend
- Create new posts in bulk using existing post
- Problem with adding programmatically woocommerce product post into category
- Post id algorithm in WordPress
- Show the content that is after the excerpt using child theme
- How to put link in twenty fourteen theme? [closed]
- Change target of view link in admin
- Switch to page template when using post permalink
- how to add older post to new wordpress post with new post?
- How not display particular post?
- WordPress Comment posting problem
- Pasting code into WordPress post – LFs being eaten
- Insert sometext after first h3 in content
- Remove password protected posts from default RSS feed
- Using setup_postdata() with multi-dimensional array
- Deleting post specific content at beginning of post
- Change Post Title For Specific Category
- Post Title to featured Image ALT
- How to display the requested post only?
- Export all posts to import as product items
- WordPress as CMS: How to manage/handle images assigned to a post as full-sized background images in a slideshow?
- Prevent duplicate pages from being added
- Can I style single post that are in multiple catergories?
- Older blog posts not showing up on WordPress
- Embedding Post Editor Into External Site
- Show single post child category from a determined parent
- Go back to the exact post page number
- Pagination Stops
- How to mark only one post as Featured post?
- Remove status ‘archived’ from the default post and page view
- How to invoke a HTML custom button based on a HTML dropdownlist menu
- Post data across WordPress sites
- Custom Post Types and Broken Permalinks
- The first post appears twice
- how to call recent post content in a loop ( only the content before read more tag)
- Find post tags words in post content and link them to tag URLs
- How can I filter the post of a CPT by taxonomy Term in admin meta-box dropdown?
- Show Posts By Custom Field
- Hide title in Merlin Theme on posts and pages only
- Custom plugin to get related posts by category
- is_archive() not working on selected “Posts page”
- Relative Image Urls in Posts are starting from root – Not from WordPress Address (URL) at General Settings
- How to associate media with a post?
- Why I obtain this WP_Query strange behavior trying to select posts having a specific tag?
- form to post multiple inputs into post_content
- Apply comment to different post (not the current post) [duplicate]
- When Author add new post change default status to pending
- Adding custom fields to the Quick Edit screen – puzzled about the column concept
- How can i add new post on new page
- how to style an individual page in a category [duplicate]
- get_posts includes “auto drafts”?
- ‘posts_per_page’ => ’10’ does not show any post
- Page not found after clicking on pagination
- how to add single wordpress post to multiple wp category with different different title
- Hide post title when single post with specific category
- User submitted post
- How to add a post option in wordpress like facebook [closed]
- How edit footer copyright info? [closed]