【问题标题】:how to get wordpress posts description and caption?如何获取 wordpress 帖子的描述和标题?
【发布时间】:2014-06-16 18:36:02
【问题描述】:

我正在尝试从 wordpress 获取 5 个特色帖子,为了实现这个目标,我已经抵消了 5 个最近的帖子。我成功地获取了帖子 ID、图像。但我没能得到每个帖子的描述。我尝试了下面的代码,但它只给了我 1 个帖子描述,而不是全部 5 个。

$my_posts = get_posts(array('numberposts' => 5,
'offset'      => 5,
'orderby'     => 'post_date',
'order'       => 'DESC',
'post_type'   => 'post',
'post_status' => 'publish'));


  foreach($my_posts as $post) {

$data[] = 

    array(
       "id" => $post->ID,
      "title" => $post->post_title,
      "image" => get_the_post_thumbnail($post->ID),
     // "content" =>$post['post_excerpt'] 
      "content" => apply_filters('the_content', $post->post_content)
    );
                       }

【问题讨论】:

    标签: php json api wordpress


    【解决方案1】:

    您会在循环中获得描述 the_content() 函数。有关此功能的更多信息在this页面上

    对于标题,您可以在循环中使用 the_excerpt() 函数

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-08
      • 1970-01-01
      • 2010-12-04
      • 2011-09-01
      • 2015-09-28
      • 1970-01-01
      相关资源
      最近更新 更多