Advertisement
MrPauloeN

Shortcode - wyświetlanie wpisów według kategorii

Jan 18th, 2021 (edited)
973
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.55 KB | None | 0 0
  1. function kod(){
  2.  
  3.     $args = array(
  4.       'category' => 82, // ID danej kategorii
  5.         'posts_per_page' => -1, // wszystkie wpisy
  6.         'post_status'      => 'publish',
  7.     );
  8.  
  9.     $posts = get_posts( $args );
  10.  
  11.     $output = '';
  12.  
  13.     foreach ( $posts as $post ) :
  14.         setup_postdata( $post );
  15.         $output .= '<p>';
  16.         $output .=  '<a href="' . get_the_permalink( $post ). '">' . get_the_title( $post ) . '</a><br/>';
  17.         $output .= get_the_excerpt( $post );
  18.         $output .= '</p>';
  19.  
  20.     endforeach;
  21.     wp_reset_postdata();
  22.    
  23. return $output;
  24.  
  25. }
  26. add_shortcode( 'kod', 'kod' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement