Use get_posts with posts_per_page => 1
to get only one latest result. You can than use get_permalink()
to get the permalink.
$args = array(
'posts_per_page' => 1,
'orderby' => 'date',
'order' => 'DESC',
) ;
$latest_posts = get_posts($args);
$permalink = get_permalink($latest_posts[0]->ID);
Related Posts:
- How to display already created menus via php?
- understand what code is doing when prepending /blog
- Custom URL for multiple categories hierarchy
- WordPress redirects to localhost
- Adding an Anchor Link to a wordpress menu using WPBakery Page Builder
- Providin exception to WordPress wp_nav_menu Custom CSS Classes
- Allow two posts (from different categories) to have the same slug
- Test the existence of a page/article by its URL, taking in consideration the URL rewriting by filters
- 404 on old link after changing post url
- Adding markup to sub menu based on class
- Featured image in menu wordpres
- How to make only the valid active page of a multilevel menu active with – “.nav li.current-menu-item a”?
- url not using query string no longer working
- Replace jQuery with PHP or CSS for Customized WordPress wp_nav_menu
- Custom PHP form needs refresh to load page correctly
- Child-Theme Category View with modified permalinks (%category% removed)
- dynamic php menu with hidden sub-categories only showing when the category name is clicked
- How to set Nav as a default menu in wordpress
- Rewrite rule not working, but only when parameter is text
- How to put 2 php codes in functions.php without site crashing
- How does Permalink work with the AMP plugin after Removing Parent Permalink Catalog from Posts
- Get WordPress username to customize url
- Menu not updating for logged in users after redirect
- Permalink doesn’t navigate to post (changes only url)
- wp_get_nav_menu_items() with ACF
- Post permalink buttons all going to the first post
- Permalink changes after several minutes after saving post
- How to edit button permalink inside function.php using a child theme?
- How to switch between two primary menus (programatically0
- How to let mobile navigation menu close when link is clicked?
- Redirect User when they click Menu Option
- Used a code to revoke some dashboard menus for my contributors but for some reason it’s revoked me access to the editor [closed]
- Get Child of Child Pages in custom Menu
- WordPress/NGINX not respecting the category URL for new posts
- WordPress generates weird permalinks
- How to give custom roles the capability to edit one Menu instead of every Menu
- Primary navigation menu with timed items from custom post type
- PHP warning with code for nav menu walker [duplicate]
- Add element after navigation element title don’t works like I expect
- Permalink like example.com/taxonomy/post_type/postname
- How to disable sub menu items from being created?
- String replace for Login/Logout concatenation problem in menu
- How do I stop my form from adding code to current page URL instead of re-directing. Been stuck for days
- image on homepage disappeared due to change of permalink name
- Bring Font Awesome icons inside menu A tags
- Difference between “Walker_Nav_menu” and “walker”
- Add parent menu item in sub-menu in custom nav_walker
- Custom content using in_category
- How to create a sub-page of sub-page?
- What is the proper way to call a function (from functions.php) on a link click?
- Fatal error when using array_diff() function inside of wp_update_nav_menu hook?
- Vertical Menu for one page only
- Display specific main Sub Nav on Woocommerce product pages
- How do I generate formatted permalinks as specified in backend options?
- PHP drop down menu for my get_category child of
- 403 Forbidden Localhost Wamp Apache Php
- Widget Logic – display on page and all child
- How limit the width of a fixed menu-bar on scroll?
- Pulling a variable into the wp_nav_menu function
- Beyond widget side menu editing, with the php page, custom template
- How to list categories by page id in wordpress
- Adding button to wordpress menu
- redirect 301 with special character like WIX site “#!”
- Permalinks and custom PHP application
- How to solve 404 permalink errors on nginx server
- Some links broken after updating WordPress version
- Editing existing pre-created menus in PHP
- Two theme locations for two menus, but only one is showing up
- add_rewrite_rule questions
- wp_nav_menu doesn’t work in a duplicate server
- Open WordPress Page from selected option dropdown
- Inserting a shortcode into a genesis menu?
- WordPress add parameters with friendly url structure
- Remove Unused Menu Locations
- Add any username as link prefix and show data from that specific user’s profile on wordpress pages – with no login required
- Custom Navigation Bar JSON Syntax Error in JSON at Position 0
- how to goto specific page number including title with permalink
- How to extract URLs from wordpress taxonomies
- WordPress 6.1.1 UTF8 Slug Limit Increase
- why css file not link?how to create permalink?
- How to add different menu items on different menus?
- Custom nav with bootstrap dropdown
- Nav menù doesn’t display selected pages
- How to automatically flush permalinks?
- Show a text in menu
- Execute wp_after_insert_post after the permalink is customized
- WordPress CPT & Custom Taxonomy with the SAME Permalink Structure
- make my custom theme support polylang plugin
- Remove slug of multiple custom post types with and without hierarchical
- Modify the permalink structure for a specific category
- change the blog in the url if you go from a specific page wordpress
- Is it possible to go to the next post in the same category?
- Can’t assign menu parent id or menu item breaks
- What is considered good practice for registering menu locations?
- How to Customize the Admin Sidebar Menu in WordPress Multisite Network by changing the backend code of the wp-admin code files?
- WordPress per ACF – permalink is not working
- Processing data and redirecting with query string
- I’ve added SKU to Woocommerce permalinks, but I have small issue
- Post returns 404 after changing the permalink using post_type_link
- Cannot access the other pages after successfully editing post type