kalponikoronno

post_list_shortcode

Mar 6th, 2018
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.72 KB | None | 0 0
  1. function wow_theme_post_list_shortcode($atts){
  2.    
  3.     extract(shortcode_atts(array(
  4.        
  5.        'count' => -1,
  6.        'post' => 'page'
  7.        
  8.     ), $atts));
  9.    
  10.     $q = new WP_Query(array(
  11.         'post_type' => $post,
  12.         'posts_per_page' => $count
  13.     ));
  14.    
  15.     $list = '<ul>';
  16.    
  17.         while($q->have_posts()) : $q->the_post();
  18.  
  19.             $idd = get_the_ID();
  20.             $custom_field = get_post_meta( $idd, 'custom_field', true );
  21.             $post_content = get_the_content();
  22.  
  23.             $list .= '<li><a href="'.esc_url(get_permalink()).'">'.get_the_title($idd).'</a></li>';
  24.  
  25.         endwhile;
  26.     $list .= '</ul>';
  27.    
  28.     wp_reset_query();
  29.    
  30.     return $list;
  31.    
  32.    
  33. }
  34. add_shortcode('post_list', 'wow_theme_post_list_shortcode');
Advertisement
Add Comment
Please, Sign In to add comment