WordPress.org

Ready to get started?Download WordPress

Forums

How to retrieve URL of any post or page with PHP? (3 posts)

  1. somlor
    Member
    Posted 7 years ago #

    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

  2. somlor
    Member
    Posted 7 years ago #

    anyone?

  3. jugularbean
    Member
    Posted 7 years ago #

    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;

Topic Closed

This topic has been closed to new replies.

About this Topic