我有一个专门的(和文档)功能:
get_page_by_path( $page_path, $output, $post_type );
Run Code Online (Sandbox Code Playgroud)
检索给定其路径的页面.
哪里$page_path是
[...]相当于'pagename'查询,如:'index.php?pagename = parent-page/sub-page'.
请参阅函数参考/按路径获取页面
例:
// Assume 'my_permalink' is a post.
// But all types are supported: post, page, attachment, custom post type, etc.
// See http://codex.wordpress.org/Post_Types
get_page_by_path('my_permalink', OBJECT, 'post');
Run Code Online (Sandbox Code Playgroud)