Adding short code to Custom post types
-
I have set up a Custom post type and I’m wanting to create a short code to display the title and content of that CPT in various places
The code below works but any page that contains the short code then has comments enabled even when settings say comments not allowed.
How can I stop this causing the comments to appear?
/* -----Shortcode Testimonials ----- */ add_shortcode( 'testimonials', 'display_testimonials' ); function display_testimonials($atts){ global $post; $html= '<div class="testimonials"> <ul>'; $args = array( 'post_type' => 'testimonial', 'post_status' => 'publish', 'tax_query' => array( array( 'taxonomy' => 'testimonial_category', 'field' => 'slug', 'terms' => $atts['category'] ) ) ); $the_query = new WP_Query( $args ); if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); $html.= '<li> '.get_the_content().' <span class="byline">'.get_the_title().'</span> </li>'; endwhile; endif; $html.= '</ul> </div>'; return $html; }
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
The topic ‘Adding short code to Custom post types’ is closed to new replies.