WordPress and buddypress programming

list updated posts pages with a short code

Viewing 0 reply threads
  • Author
    Posts
    • #2469
      michael mc
      Keymaster
      @michael
      // list updated posts pages
      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.