how to get wordpress posts description and caption?

17,875

You get the description the_content() function within the loop. More information about this function is on this page

For caption, you could use the_excerpt() function with the loop

Share:
17,875

Related videos on Youtube

warzone_fz
Author by

warzone_fz

Updated on June 04, 2022

Comments

  • warzone_fz
    warzone_fz almost 2 years

    Iam trying to get 5 featured post from wordpress, to achieve this target i have offset 5 recent post .I successfully fetched post id , images . But i failed to get every posts description .i tried the code below but it only give me only 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)
        );
                           }