prepare_payment()
正在呼叫wp_get_recent_posts()
默认情况下,返回post数组。在这种情况下,由于$numberposts
参数设置为1
.
$recent_posts
保存由返回的帖子数组wp_get_recent_posts()
. 以下行正在设置$thePostID
中第一个帖子的ID$recent_posts
阵列(arrays are zero indexed):
$thePostID = $recent_posts[0][\'ID\'];
最后,使用该行回显ID
echo $thePostID;
编辑:以下是返回的数组示例wp_get_recent_posts()
, 它本身就是get_posts()
.`
Array
(
[0] => Array
(
[ID] => 418
[post_author] => 2
[post_date] => 2025-01-01 00:00:00
[post_date_gmt] => 2025-01-01 00:00:00
[post_content] => This post is scheduled to be published in the future.
It should not be displayed by the theme.
[post_title] => Scheduled
[post_excerpt] =>
[post_status] => future
[comment_status] => open
[ping_status] => closed
[post_password] =>
[post_name] => scheduled
[to_ping] =>
[pinged] =>
[post_modified] => 2016-04-11 04:28:22
[post_modified_gmt] => 2016-04-11 04:28:22
[post_content_filtered] =>
[post_parent] => 0
[guid] => http://wpthemetestdata.wordpress.com/?p=418
[menu_order] => 0
[post_type] => post
[post_mime_type] =>
[comment_count] => 0
[filter] => raw
)
)
您可以通过将一个简单的调试语句添加到
prepare_payment()
:
function prepare_payment() {
$recent_posts = wp_get_recent_posts( array( \'numberposts\' => \'1\' ) );
// Temporary debugging statement
print_r( $recent_posts );
$thePostID = $recent_posts[0][\'ID\'];
echo $thePostID;
}