gpt4 book ai didi

php - 如何从 WP_Post 对象获取标题

转载 作者:可可西里 更新时间:2023-11-01 12:30:20 26 4
gpt4 key购买 nike

我试图查看子页面名称列表以及一些要显示的描述..我使用下面的代码

$my_wp_query = new WP_Query();
$all_wp_pages = $my_wp_query->query(array('post_type' => 'page'));
// Get the page as an Object
$portfolio = get_page_by_title('service');
// Filter through all pages and find Portfolio's children
$portfolio_children = get_page_children( $portfolio->ID, $all_wp_pages );
// echo what we get back from WP to the browser
echo "<pre>";print_r(
);

foreach($portfolio_children as $pagedet):

echo $pagedet['post_title'];


endforeach;

我在使用 foreach 之前获取数组

when i print  $portfolio_children iam getting out put like this 
Array
(
[0] => WP_Post Object
(
[ID] => 201
[post_title] => Website Hosting
)
[1]=> WP_Post Object

(
[ID] => 202
[post_title] => Website
)

在 foreach 之后如果我打印 $pagedet iam getting

WP_Post Object
(
[ID] => 201
[post_title] => Website Hosting
)

我试着调用 $pagedet['post_title'] 但 id 没有显示任何东西...提前致谢

最佳答案

为了确定,您应该使用每个页面数据作为列名。

例如,

$page_data->post_content //is true,
$page_data->the_title // is false.

关于php - 如何从 WP_Post 对象获取标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18077278/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com