$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>Extracting the permalink from a post instance|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

Extracting the permalink from a post instance

matteradmin8PV0评论

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);

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far