WordPress 通过文章 URL 获取文章 ID

// 获取当前文章链接,注意,在文章类型页面的主循环外使用标签时,如果没有指定 Post ID 参数,该标签将返回循环中最后一篇文章的 URL,而不是当前页面的固定链接,或者直接不返回结果,所以一般需要指定 Post ID
echo get_permalink();

// 该
函数只需要传入 URL 字符串即可返回整型 Post ID,如果文章不存在则返回0。
// 注意:有时候获取的 URL 被 urlencode 编码了,那么传入的 URL 参数记得用 urldecode 解码
url_to_postid(string $url)

https://developer.wordpress.org/reference/functions/get_permalink/

https://wpml.org/forums/topic/how-to-get-post-id-from-the-current-post-permalink/

原文地址:https://www.cnblogs.com/ryanzheng/p/10517951.html