WordPress.org

Support

Support » Themes and Templates » Why get_permalink is not working?

Why get_permalink is not working?

  • Hi,

    am trying to get popular posts from the db

    function get_popularposts{
    // other code ....
    foreach($myposts as $post) {
    $thePostID = $post->ID;
    $sLink = get_permalink($post->ID);
    //echo get_permalink($post->ID);
    // $sLink = get_permalink($thePostID);
    // other code ....
    }
    }

    Here $thePostID returns the correct post id. $sLink returns the domain name instead of post url. It returns the correct url in Localhost (in my local system). However, it returns the domain name when I upload it into web.

Viewing 4 replies - 1 through 4 (of 4 total)
  • can someone help on this please ?

    thanks

    Without seeing more of the code it could be any number of things…

    Sounds like you’re having loop problems…

    Are you creating a new WP Query for the popular posts list?

    I believe I am not getting any loop problems. I am getting the post id correctly

    echo $thePostID;

    the above code prints the correct post id. I am getting the content from the post correctly. am getting the custom fields correctly. The only issue is with the links.

    also it works great in my local machine .. am getting the correct permalinks. Only on web, it doesn’t return the correct permalinks url.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Why get_permalink is not working?’ is closed to new replies.
Skip to toolbar