WordPress根据页面标题获取页面对象函数:get_page_by_title
WordPress函数get_page_by_title根据页面标题获取页面对象,如果有相同名称标题的页面,则…
WordPress函数get_page_by_title根据页面标题获取页面对象,如果有相同名称标题的页面,则返回最早发布的页面。
get_page_by_title( string $page_title, string $output = OBJECT, string|array $post_type = 'page' )
函数参数
$page_title
字符串
页面标题
$output
字符串
返回数据的类型,可用值如下:
- OBJECT:返回对象;
- ARRAY_A:返回关联数组;
- ARRAY_N:返回数值数组;
$post_type
字符串,默认值:page
文章类型
函数返回值
WP_Post Object ( [ID] => 2 [post_author] => 1 [post_date] => 2020-11-27 11:37:03 [post_date_gmt] => 2020-11-27 03:37:03 [post_content] => [post_title] => 关于我们 [post_excerpt] => [post_status] => publish [comment_status] => closed [ping_status] => closed [post_password] => [post_name] => about [to_ping] => [pinged] => [post_modified] => 2020-11-27 14:45:21 [post_modified_gmt] => 2020-11-27 06:45:21 [post_content_filtered] => [post_parent] => 0 [guid] => https://www.beizigen.com/?page_id=2 [menu_order] => 0 [post_type] => page [post_mime_type] => [comment_count] => 0 [filter] => raw )
函数使用示例
$pages = get_page_by_title('关于我们'); echo '<a href="' . get_page_link($pages->ID) . '">' . $pages->post_title . '</a>';
扩展阅读
get_page_by_title()函数位于:wp-includes/post.php
相关函数:
- get_post()
- get_page_by_path()
类别:WordPress函数讲解、
本文收集自互联网,转载请注明来源。
如有侵权,请联系 wper_net@163.com 删除。
还没有任何评论,赶紧来占个楼吧!