Get URL from slug (2 posts)

  1. David Potter
    Posted 7 years ago #

    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'))?


  2. s_ha_dum
    Posted 7 years ago #

    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'.

Topic Closed

This topic has been closed to new replies.

About this Topic