rajudhaka

Shortcode inside custom post

Jul 20th, 2019
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.88 KB | None | 0 0
  1. function post_list_shortcode($atts){
  2.     extract( shortcode_atts( array(
  3.         'count' => '',
  4.     ), $atts) );
  5.      
  6.     $q = new WP_Query(
  7.         array('posts_per_page' => $count, 'post_type' => 'posttype', 'orderby' => 'menu_order','order' => 'ASC')
  8.         );      
  9.          
  10.     $list = '<div class="custom_post_list">';
  11.     while($q->have_posts()) : $q->the_post();
  12.         $idd = get_the_ID();
  13.         $custom_field = get_post_meta($idd, 'custom_field', true);
  14.         $post_content = get_the_content();
  15.         $list .= '
  16.        <div class="single_post_item">
  17.            <h2>' .do_shortcode( get_the_title() ). '</h2>
  18.            '.wpautop( $post_content ).'
  19.            <p>'.$custom_field.'</p>
  20.        </div>
  21.        ';        
  22.     endwhile;
  23.     $list.= '</div>';
  24.     wp_reset_query();
  25.     return $list;
  26. }
  27. add_shortcode('post_list', 'post_list_shortcode');
Advertisement
Add Comment
Please, Sign In to add comment