80 Get Page Url Wordpress By Slug Update

If you return the id from the post table then you can create an instance of wp post from it and that resolves directly in all of the wordpress functions that check for other values wp post also provides methods directly to find most related data about the post.
Get page url wordpress by slug. Get page id or url from a slug in wordpress. We recommend choosing an option in which the url contains relevant words. Returns the animal with the slug cat get page by path cat object animal.
What is a url slug. Think of a url as an address. It requires post provided explicitly and doesn t default to the current one so in full for the current post it would be.
Note that this only works with the right permalink settings. Returns nothing assumes animals is the rewrite slug for the animal cpt get page by path animals cat object animal. Most simply a post s or page s slug can be retrieved by accessing the global post object s post name property.
Here is a handy snippet with which you can easily get the current page url on your wordpress website regardless of the page which is being displayed. While it could be accessed directly i prefer the underused get post field function for accessing post properties which have no proper api for them. You can edit the permalink settings in wordpress through settings permalinks.
This is interesting with years experience working with wordpress i ve never dealt with this kind of issue. Imagine the domain is the apartment building and each page is a different apartment. As per other answers slug is stored in the post name property.
There are several ways to get the current page s or post s slug in wordpress. Changing search page url slug in wordpress. June 27 2020 reading time.