easy to do with get_posts
// search the last post
$posts = get_posts([
"posts_per_page" => 1,
]);
foreach ($posts as $p) {
// display the permalink
echo esc_html(get_permalink($p));
}
documentation of get_posts
:
https://codex.wordpress.org/Function_Reference/get_posts
Related Posts:
- WP move posts to different path
- How to generate an HTML link automatically from URL in a users’ post
- Access post from post id in URL
- How to add category to: ‘wp-admin/post-new.php’?
- How to Check if a Page Exists by URL?
- How do you get all the urls of images attached to a post?
- how to display full post with pagination on home page
- blog page showing only first post
- How to allow slashes in single posts when i click in the edit permalink button
- Possible to create a permalink to sort with meta_key?
- how to grab first link in post… and of course call it
- Single Post Gallery Using Shortcode
- Showing random content / pictures from earlier posts in a sticky post?
- Side by side blog posts that are tied together
- How to show a full post, not just an excerpt
- Remove slashes (both before and after) in relative post url
- Blog Posts not showing title
- Paginated Posts – Social Media Buttons Share First Page URL
- Why is my Blog Page ID == First Post ID?
- WordPress not opening posts with only numbers if permalink is post_name
- Displaying Latest Posts on a Page
- How to make number of blog posts a custom field?
- How can i display gallery shortcode output under Post text
- Display posts from a different website on Genesis Responsive Slider
- WP Bakery Load More Button loads the same posts
- Assign category to new post via URL
- add new post default view
- Show certain posts in a LIST format that members have been granted access to
- filter RSS feed in URL
- Posting blog entries in screenplay format
- Retrieve post ID from “querying” URL
- Single.php – Get Current Parent Category
- Linking to pages/posts within the site
- Make insterted image point to post url instead of attachment page
- How to create a page that shows the last 10 posts?
- Exclude post category in a blog page
- How to set a certain Custom Template to a Single Blog Post
- Sidebar on single.php not showing up
- Where is the “Posts”/”Blog” template?
- Inserting Media to WordPress Posts
- Custom Post Type, post-formats associated to custom post type > 404 archives
- How to separate each individual blog post?
- Direct some posts to only appear on a specific page
- posts and cms and posts again
- Separate blog and reviews categories
- How to prevent to create same url of post, if the previous was deleted?
- Create a List of Widgets, where each widget holds three attributes
- WordPress posts have a different URL to the index
- Older blog posts not showing up on WordPress
- Pagination not give another posts
- “Blog pages show at most” in setting not working
- How to bulk Update URLs to new values?
- Permalink Short code showing unnecessary link text inside the loop
- Post Image Gallery After Content Function messes with other content
- How can I create a ‘sub-blog’ which has its own sidebar on individual posts?
- How can I make a post sub link?
- How to pull sticky post permalink inside php?
- WordPress empty page! what is wrong with this code?
- Use posts from old db by changing prefix
- Pagination Stops
- Bulk find & replace on WordPress posts/pages (minus image paths)
- How to backup WP blog posts to computer, not new site
- Does having category name in permalinks affect SEO when having a post in multiple categories?
- Customizing a new page used for blog posts with Avada theme
- Blog images not showing on homepage
- Blog Page doesn’t show summary but full content
- Change WordPress names duplicate titles (url)
- Get posts from category from custom query
- My posts page is missing the page title
- Blog Post slider not working
- Multiple Pages – Seperate blogs
- Word /blog/ in slug post, problems in CPT. Solutions?
- Querying posts from current category, using a variable as array argument
- How to put the WordPress blog into theme
- If I moved the location of my generic “posts” page, do I need to change the slugs for all of the individual posts?
- Multipage Post URL correction
- WordPress URL question
- Edit Posts Page but not category specific pages?
- How to change post template via url?
- How to retrieve a post by inputing the url in a custom field and displaying it on an options page
- Post as frontpage – avoid duplicate content
- Blog styling in SASS
- Is there a Standard Format for Clean URLs for Archives of Custom Posts?
- How can I have the posts from one word press blog show on the presentation page of another word press site
- Moving Posts to a new site and maintaining URLs
- Change the default video URL in a post to shortcode format
- Posts don’t appear on the Blog page
- Get image paths from RSS feeds
- 2 tick boxes appearing below comments
- Choose options via url
- long blog post on self hosted wordpress blog not displayed
- WordPress Custom Theme: My site shows the same posts on Page 1 and Page 2 and so on [duplicate]
- The page that displays Posts on homepage
- How to add a widget area between blog posts in Genesis Framework?
- Default post type doesn’t display in url
- Do I need to create a multisite for querying posts from multiple WordPress sites?
- Need to show birthday of custom post type(Famous people in this case) in elementor. Date of birth set in custom fields
- Post page still linked to old site
- Blog posts are not appearing as subs of Blog Page
- How to add paraent in Blog post URL in wordpress