WordPress获取页面信息函数:get_page_by_title

描述

wordpress通过文章标题获取页面信息,如果多个文章标题一致返回id最小的文章信息。

使用

<?php
  get_page_by_title( $page_title, $output, $post_type );
?>

参数

$page_title (string) (必须) 文章标题     Default: None

$output (string) (optional) 返回值类型. OBJECT, ARRAY_N, or ARRAY_A.       Default: OBJECT

$post_type  (string) (optional) 文章类型     Default: page

返回的值

ID          int     文章 ID
post_author     string  作者 user ID
post_name   string  文章别名
post_type   string  文章类型
post_title  string  文章标题
post_date   string  文章时间,格式为: 0000-00-00 00:00:00
post_date_gmt   string 文章 gmt 时间,格式为,: 0000-00-00 00:00:00
post_content    string  文章内容
post_excerpt    string  文章摘要
post_status     string  文章状态
comment_status  string  评论状态,开启或者关闭: { open, closed }
ping_status     string  ping 状态 { open, closed }
post_password   string  文章密码
post_parent     int     父 ID,默认是 0
post_modified   string  文章修改时间,格式为: 0000-00-00 00:00:00
post_modified_gmt   string  文章修改时间,格式为: 0000-00-00 00:00:00
comment_count   string  文章评论统计
menu_order  string  好像没什么用,默认是 0

示例

//WordPress 通过文章标题获取 post 信息
$post = get_page_by_title('这里就是文章的标题', OBJECT, 'post');
$postid = $post->ID; //文章 ID

源文件

get_page_by_title() 位于wp-includes/post.php.