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

前端之家收集整理的这篇文章主要介绍了php – 如何从WP_Post对象获取标题前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我试图看到子页面列表名称与一些描述显示..i使用下面的代码
$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我得到

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.
原文链接:https://www.f2er.com/php/134799.html

猜你在找的PHP相关文章