首页 WordPress函数 WordPress获取文章数据函数:get_post
正文 评论

WordPress获取文章数据函数:get_post

WordPress函数get_post用于获取文章的数据,包括文章内容、标题、别名、摘要、发布时间等信息。

get_post( int $post = null, string $output = OBJECT, string $filter = \'raw\' )

函数参数

$post

整数型,默认值:null

文章的ID,或对象

$output

字符串值,默认值:OBJECT

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

  • OBJECT:对象;
  • ARRAY_A:数组,升序排列;
  • ARRAY_N:数组,降序排列;

$filter

字符串值,默认值:raw

要应用的过滤类型

函数返回值

WP_Post Object ([ID] => 121[post_author] => 1[post_date] => 2017-11-28 21:44:29[post_date_gmt] => 2017-11-28 13:44:29[post_content] => 文章内容[post_title] => 文章标题[post_excerpt] => 文章摘要[post_status] => publish[comment_status] => open[ping_status] => closed[post_password] =>[post_name] => 文章别名[to_ping] =>[pinged] =>[post_modified] => 2018-04-08 09:04:53[post_modified_gmt] => 2018-04-08 01:04:53[post_content_filtered] =>[post_parent] => 0[guid] => https://www.beizigen.com/?p=121[menu_order] => 0[post_type] => post[post_mime_type] =>[comment_count] => 0[filter] => raw)

注意返回的guid为文章原始链接,即动态URL,不会返回伪静态链接。

函数使用示例

<?php$post = get_post( 8 );$title = $post->post_title;$excerpt = $post->post_excerpt;$content = $post->post_content;?>

扩展阅读

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

相关函数:

  • get_posts()
  • sanitize_post()
-=||=-收藏赞 (0)
更多主题
v1.0.0
小程序收录免费WordPress主题:XCX主题
¥ 0 关注:23,601
详情
单栏极简文艺WordPress博客主题:Diaspora主题
¥ 0 关注:22,587
详情
简约黑白WordPress个人博客主题:Personal主题
¥ 0 关注:22,340
详情
功能丰富切轻量的WordPress虚拟资源主题:Rizhuti主题
¥ 599 关注:20,522
详情
v1.0.0
一款简约单栏的免费WordPress博客主题:itheme主题
¥ 0 关注:20,452
详情
WordPress版WebStack导航主题:WebStack主题
¥ 0 关注:18,856
详情
回复
暂无评论

不要再留垃圾评论了,主题君整理资源不容易,留几句鼓励的话吧。