WordPress.org

Ready to get started?Download WordPress

Forums

Get URL from slug (2 posts)

  1. David Potter
    Member
    Posted 5 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'))?

    Thanks,
    David

  2. s_ha_dum
    Member
    Posted 5 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

Tags