Extracting the permalink from a post instance

admin2025-06-04  0

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()?

Share Improve this question edited Jan 2, 2019 at 1:49 Keith John Hutchison asked Jan 2, 2019 at 1:12 Keith John HutchisonKeith John Hutchison 1013 bronze badges 2
  • 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
Add a comment  | 

1 Answer 1

Reset to default 0

Thanks to Tom's suggestion of searching for permalink instead of pretty URLs I found the get_permalink function.

$permalink = get_permalink($post->ID);
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1749052792a315952.html

最新回复(0)