I'm exporting some posts from a WordPress site.
One of the attributes of a post instance derived from $posts = get_posts();
is guid .. $post->guid
which shows how to find the original post. Something like /?p=2152
When I go to a browser and paste in the guid URL it often redirects to the permalink URL which is the URL I'd like to reference back to.
How do you extract the permalink from a post instance derived from get_posts()
?
I'm exporting some posts from a WordPress site.
One of the attributes of a post instance derived from $posts = get_posts();
is guid .. $post->guid
which shows how to find the original post. Something like https://www.domain.au/?p=2152
When I go to a browser and paste in the guid URL it often redirects to the permalink URL which is the URL I'd like to reference back to.
How do you extract the permalink from a post instance derived from get_posts()
?
- 1 the pretty URL is also known as the permalink, you'll get a lot more/better results trying to search with permalink rather than pretty URL. Also, GUIDs aren't always URLs, or the current URL of the post, don't trust them blindly – Tom J Nowell ♦ Commented Jan 2, 2019 at 1:23
- Thanks @TomJNowell. permalink searching was fruitful. – Keith John Hutchison Commented Jan 2, 2019 at 2:08
1 Answer
Reset to default 0Thanks to Tom's suggestion of searching for permalink instead of pretty URLs I found the get_permalink function.
$permalink = get_permalink($post->ID);