WordPress获取文章数据函数:get_post

WordPress函数get_post用于获取文章的数据,包括文章内容、标题、别名、摘要、发布时间等信息。get_post( int $post = null, string $output = OBJECT, string $filter = 'raw' )函数参数$post整数型,默认值:null文章的ID,或对象...

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,不会返回伪静态链接。

get_post()函数使用示例

<?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()

给TA打赏
共{{data.count}}人
人已打赏
wordpress教程

WordPress网站更新内容时怎么查找内容源?

2023-2-16 15:55:40

wordpress教程

如何升级Linux 服务器上所有的 WordPress 站点?

2023-2-16 15:55:41

【腾讯云】11.11云上盛惠!云服务器首年1.8折起,买1年送3个月!
11.11云上盛惠!海量产品·轻松上云!云服务器首年1.8折起,买1年送3个月!超值优惠,性能稳定,让您的云端之旅更加畅享。
查看更多相关信息>>
在线咨询
站长

(工作日 10:00 - 22:30 为您服务)

2026-07-07 23:49:57

您好,无论是售前、售后、意见建议……均可通过联系工单与我们取得联系。

猜你想问:

  • 购买的模板免费包安装吗?

  • 这个演示地址有吗?

  • 购买vip会员可以下载哪些模板?

您的留言我们已经收到,我们将会尽快跟您联系!
取消
立即选择任一渠道联系我们