Support » Themes and Templates » Get URL from slug

  • How do I get the URL if I have the slug?

    I’m implementing a feature on a theme where the admin can specify the link to use for an image. I want to allow them to specify either an explicit HTTP address or select a page. If they select a page, I only want to store the slug so that they can move the page to a different location if they want and it will still work.

    Is there a function in WP that takes a slug and returns the full URL, or even partial URL (meaning I’d need to call get_setting(‘home’))?


Viewing 1 replies (of 1 total)
  • The slug is the post_name value in the wp_posts table. A simple query should get it for you– SELECT guid FROM wp_posts WHERE post_name = 'whatever'.

Viewing 1 replies (of 1 total)
  • The topic ‘Get URL from slug’ is closed to new replies.