Support » Fixing WordPress » How to retrieve URL of any post or page with PHP?

  • somlor

    (@somlor)


    I am working on a very dynamic design that has a lot of links to pages in the header and sidebar. I would like to have the flexibility to change the page slugs and parent/child relationships later, without breaking all these links. Can someone help me whip up some PHP to retrieve the current URL of any page based on it’s id number?

    Thanks!
    Sean

Viewing 2 replies - 1 through 2 (of 2 total)
  • somlor

    (@somlor)

    anyone?

    jugularbean

    (@jugularbean)

    assuming your id is stored in the variable $id the following should work.

    $url = $wpdb->get_results("SELECT guid FROM $wpdb->posts WHERE ID = $id");
    echo $url->guid;
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to retrieve URL of any post or page with PHP?’ is closed to new replies.