WordPress.org

Ready to get started?Download WordPress

Forums

Why get_permalink is not working? (5 posts)

  1. Asapcorp
    Member
    Posted 5 years ago #

    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.

  2. Asapcorp
    Member
    Posted 5 years ago #

    can someone help on this please ?

    thanks

  3. t31os
    Member
    Posted 5 years ago #

    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?

  4. Asapcorp
    Member
    Posted 5 years ago #

    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.

  5. Asapcorp
    Member
    Posted 5 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic