WordPress and buddypress programming

How to Display a List of Last Updated Posts in WordPress

Viewing 0 reply threads
  • Author
    Posts
    • #1365
      michael mc
      Keymaster
      @michael
      function wpb_lastupdated_posts() { 
       
      // Query Arguments
      $lastupdated_args = array(
      'orderby' => 'modified',
      'ignore_sticky_posts' => '1'
      );
       
      //Loop to display 5 recently updated posts
      $lastupdated_loop = new WP_Query( $lastupdated_args );
      $counter = 1;
      $string .= '<ul>';
      while( $lastupdated_loop->have_posts() && $counter < 5 ) : $lastupdated_loop->the_post();
      $string .= '<li><a href="' . get_permalink( $lastupdated_loop->post->ID ) . '"> ' .get_the_title( $lastupdated_loop->post->ID ) . '</a> ( '. get_the_modified_date() .') </li>';
      $counter++;
      endwhile; 
      $string .= '</ul>';
      return $string;
      wp_reset_postdata(); 
      } 
       
      //add a shortcode
      add_shortcode('lastupdated-posts', 'wpb_lastupdated_posts');
Viewing 0 reply threads
  • You must be logged in to reply to this topic.