Advertisement
Guest User

Untitled

a guest
Jul 15th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. function get_last_posts() {
  2.  
  3. global $post;
  4.  
  5. $resultados = get_posts( array(
  6. 'numberposts' => 3,
  7. 'orderby' => 'date',
  8. 'order' => 'DESC',
  9. 'post_type' => 'product'
  10. ) );
  11.  
  12. // print_r( $resultados );
  13.  
  14.  
  15. $html = '<div class="row">';
  16.  
  17. if ( $resultados ) {
  18. foreach ( $resultados as $post ):
  19. setup_postdata( $post );
  20. $html .= '<div class="col-md-4">'.get_the_title().'</div>';
  21. endforeach;
  22. }
  23.  
  24.  
  25.  
  26. $html .= '</div>';
  27.  
  28. return $html;
  29.  
  30. }
  31.  
  32. function get_products_function( $atts ){
  33. return get_last_posts();
  34. }
  35.  
  36.  
  37. add_shortcode( 'get_products', 'get_products_function' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement