Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am trying to get and display 5 featured posts. To achieve this target I have an offset of 5 recent posts. I have successfully fetched the posts' id's and images, but I failed to get every post's description.

I've tried the code below, but it only gives me 1 post description, not all 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)
);
                   }
share|improve this question
    
What is a "post description"? Do you mean the excerpt? The content? Or are you talking about something added by a plugin or a custom post type with custom fields? –  kaiser Jun 16 at 23:54
    
yes i am talking about "excerpt" / "content" –  warzone_fz Jun 17 at 4:52
    
Well, there is an automated excerpt which is extracted from the content and then there is the explicit excerpt, which has it's own meta box. And please file an edit for the info you are revealing. It does belong in the question, not in an comment. Thanks. –  kaiser Jun 17 at 8:14

1 Answer 1

Something like this should get you close (untested):

<?php
    foreach($my_posts as $post){
        $thisPostId = $post->ID;
        $thisPost = $get_post($thisPostId);
        $thisPostTitle = apply_filters('the_title', $thisPost->post_title);
        $thisPostThumbnail = get_the_post_thumbnail($thisPost);
        $thisPostContent = apply_filters('the_excerpt', $thisPost->post_excerpt);

        $data[] = array(
            "id" => $thisPost,
            "title" => $thisPostTitle,
            "image" => $thisPostThumbnail,
            "content" => $thisPostContent
        );
    }
?>
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.