I want to retrieve the content of a page via ajax. but i have a problem with get_permalink

    $id = 171; 
    $post = get_post($id); 
<a class="post-link" rel="" href="<?php echo get_permalink($id); ?>">

when I echo the permalink it gives me this address


If I click in the link it gives me a page not found. If I copy paste it in the url a page not found shows. I verify the guid in the database and is the same that permalink gives me. When I watch a page in the address bar in chrome only shows me https://mysite/mypage/

Other thing I had notice in the database is that the post id change every time the page content is edited, how I can search for the id of page if it always change?

  • I think the issue is permalink, go to settings and set the permalink to post name and save it Oct 19, 2021 at 6:30

1 Answer 1


The answer lies in your question already...

When you use get_permalink for your post 171, it gets you


So, as you can see, this post is not a published post, but a revision of a post. Revisions are not public, so you can't see them...

So how to solve that?

You'll have to check the correct ID of a post you want to link to and replace 171 with that ID.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.