Simple question. I'm attempting to use get_permalink() in vanilla php but cannot access it. I have include_once all these "used" files:

  • wp-settings.php
  • wp-includes/load.php
  • wp-includes/link-template.php
  • wp-includes/rewrite.php
  • wp-includes/functions.php

and 10 other files. How do I access get_permalink()?

  • There’s no such function as get_permalinks(). It’s get_permalink(). But why do you need this in vanilla PHP? It doesn’t make sense to use outside of WordPress, and isn’t designed to be. Aug 20, 2020 at 8:00
  • I created a feature-rich search page on a client's website, she has a Wordpress install and wanted links to her blog posts, so to create those links dynamically for her ongoing recent posts I need access to the links, but Wordpress uses Apache rewrite to make those permalinks dynamically, so I came up with this workaround. I'm not a Wordpress expert.
    – stkmedia
    Aug 21, 2020 at 5:14

2 Answers 2


The developer's reference is a great place to start. You'll find get_permalink in wp-includes/link-template.php.

You might want to look into wp-cli wp post list --post__in=1 --field=url should do the trick as discussed in wp-cli issue#2727

Also, there's the rest-api to consider. The best solution for getting the permalink might be to just post/cURL a request to WordPress' rest-api to get the permalinks you want.

This question might be a good place to start: WP JSON list all permalinks

For example, you could do something like the following: curl https://example.com/wp-json/wp/v2/posts/<id> or curl https://example.com/wp-json/wp/v2/pages/<id>

& then find the guid / permalink from there.


I worked it out. This file loads Wordpress and makes functions accessible.


then was able to

$id = $rowa["ID"];  //from MySQL fetch array
$permalink = get_permalink(number_format($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.