📌  相关文章
📜  wordpress 从页面标题获取 id - PHP 代码示例

📅  最后修改于: 2022-03-11 14:54:00.500000             🧑  作者: Mango

代码示例1
//You can use OBJECT or null
/*
* RETURNS: the post array 
* post_name: is the name of the post you are looking for
* OBJECT: accepts results of WP_posts or get_posts  (i.e. $posts)
*         if you don't have and OBJECT just use null instead
* post_type: the name of your post type (i.e. 'page' or 'post'
* additional information https://developer.wordpress.org/reference/functions/get_page_by_title/
*
* ALSO get_page_by_path ('slug_name', OBJECT, 'post_type')
*/

$post = get_page_by_title( 'post_name' , OBJECT, 'post_type' );
echo $post->ID;