我同意WebElaine的评论,存储ID将更加可靠,因为URL可以很容易地更改。
也就是说,如果您有这样的URL:
http://domain.com/2018/01/this-is-my-post/
 您可以使用类似的方式获取帖子名称:
$url = \'http://domain.com/2018/05/this-is-my-post/\';
$components = parse_url($url);
preg_match(\'`^/\\d*/\\d*/(.*)/$`\', $components[\'path\'], $matches);
echo $matches[1];
 在中使用帖子名称
$matches[1] 您可以使用
get_page_by_path 获取post对象。
$post = get_page_by_path($matches[1]);
 从那里,您可以使用
$post->ID.