Forums

Get URL from slug (2 posts)

  1. DavidPotter
    Member
    Posted 8 months 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. apljdi
    Member
    Posted 8 months 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'.

Reply

You must log in to post.

About this Topic

Tags