{"id":7379548,"date":"2016-05-14T06:13:57","date_gmt":"2016-05-14T06:13:57","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/adding-short-code-to-custom-post-types\/"},"modified":"2016-08-31T17:38:09","modified_gmt":"2016-08-31T17:38:09","slug":"adding-short-code-to-custom-post-types","status":"publish","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/adding-short-code-to-custom-post-types\/","title":{"rendered":"Adding short code to Custom post types"},"content":{"rendered":"<p>I have set up a Custom post type and I&#8217;m wanting to create a short code to display the title and content of that CPT in various places<\/p>\n<p>The code below works but any page that contains the short code then has comments enabled even when settings say comments not allowed.<\/p>\n<p>How can I stop this causing the comments to appear?<\/p>\n<pre><code>\/* -----Shortcode Testimonials ----- *\/\nadd_shortcode( &#039;testimonials&#039;, &#039;display_testimonials&#039; );\nfunction display_testimonials($atts){\n\t\tglobal $post;\n\t\t$html= &#039;&lt;div class=&quot;testimonials&quot;&gt;\n\t\t\t\t\t&lt;ul&gt;&#039;;\n        $args = array(\n            &#039;post_type&#039; =&gt; &#039;testimonial&#039;,\n            &#039;post_status&#039; =&gt; &#039;publish&#039;,\n            &#039;tax_query&#039; =&gt; array(\n\t\t\tarray(\n\t\t\t\t&#039;taxonomy&#039; =&gt; &#039;testimonial_category&#039;,\n\t\t\t\t&#039;field&#039;    =&gt; &#039;slug&#039;,\n\t\t\t\t&#039;terms&#039;    =&gt; $atts[&#039;category&#039;]\n\t\t\t\t)\n\t\t\t   )\n\t\t\t);\n\n\t\t\t$the_query = new WP_Query( $args );\n\t\t\tif ( $the_query-&gt;have_posts() ) : while ( $the_query-&gt;have_posts() ) : $the_query-&gt;the_post(); \n\n\t\t\t\t$html.= &#039;&lt;li&gt;\n\t\t\t\t&#039;.get_the_content().&#039;\n\t\t\t\t&lt;span class=&quot;byline&quot;&gt;&#039;.get_the_title().&#039;&lt;\/span&gt;\n\n\t\t\t\t&lt;\/li&gt;&#039;;\n\n\t\t\tendwhile; endif;\n\t\t\t$html.= &#039;&lt;\/ul&gt;\n\t\t\t\t&lt;\/div&gt;&#039;;\n\t\t\treturn $html;\n    }<\/code><\/pre>\n","protected":false},"template":"","class_list":["post-7379548","topic","type-topic","status-publish","hentry"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/7379548","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/7379548\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=7379548"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}