php - 如何获取wordpress帖子的描述和标题?

标签 php json api wordpress

我试图从 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)
    );
                       }

最佳答案

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

对于标题,您可以将 the_excerpt() 函数与循环结合使用

关于php - 如何获取wordpress帖子的描述和标题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24250021/

相关文章:

json - ExtJS 在网格中加载嵌套的 JSON 数据

javascript - AngularJS $uibModal 不工作

c# - 插入方法应该返回一个对象还是抛出异常

python - Windows Live 登录 API SSL 问题 - Python

php - html <object> 大小以适应对象的内容

php - 如何通过关键词进行搜索? (PHP)

javascript - 如何更改 json 响应中的数据

api - 是否有指纹读取器api/sdk?

php - 来自 Google Analytics 的实时访问者。如何获得?

php - 在 Hero Framework 主题中的 .thtml 文件中执行 php