WordPress根据页面路径获取页面对象函数:get_page_by_path

WordPress函数get_page_by_path根据页面路径获取页面对象 get_page_by_pat…

WordPress函数get_page_by_path根据页面路径获取页面对象

get_page_by_path( string $page_path, string $output = OBJECT, string|array $post_type = 'page' )

函数参数

$page_path

字符串

页面的路径,不包含域名部份,例如:

/about/contact

$output

字符串

返回数据的类型,可用值如下:

  • OBJECT:返回对象;
  • ARRAY_A:返回关联数组;
  • ARRAY_N:返回数值数组;

$post_type

字符串,默认值:page

文章类型

函数返回值

WP_Post Object
(
    [ID] => 15
    [post_author] => 1
    [post_date] => 2020-11-27 16:37:42
    [post_date_gmt] => 2020-11-27 08:37:42
    [post_content] => 
    [post_title] => 联系我们
    [post_excerpt] => 
    [post_status] => publish
    [comment_status] => open
    [ping_status] => closed
    [post_password] => 
    [post_name] => contact
    [to_ping] => 
    [pinged] => 
    [post_modified] => 2021-02-22 11:00:05
    [post_modified_gmt] => 2021-02-22 03:00:05
    [post_content_filtered] => 
    [post_parent] => 2
    [guid] => https://www.beizigen.com/?page_id=15
    [menu_order] => 0
    [post_type] => page
    [post_mime_type] => 
    [comment_count] => 0
    [filter] => raw
)

函数使用示例

$pages = get_page_by_path('/about/contact');
echo '<a href="' . get_page_link($pages->ID) . '">' . $pages->post_title . '</a>';

扩展阅读

get_page_by_path()函数位于:wp-includes/post.php

相关函数:

  • get_post()
  • get_post_embed_url()
  • get_page_by_title()
类别:WordPress函数讲解

本文收集自互联网,转载请注明来源。
如有侵权,请联系 wper_net@163.com 删除。

评论 (0)COMMENT

登录 账号发表你的看法,还没有账号?立即免费 注册