{"id":12170695,"date":"2020-09-06T15:56:07","date_gmt":"2020-09-06T13:56:07","guid":{"rendered":"https:\/\/it.wordpress.org\/support\/topic\/eseguire-una-query-solo-per-una-pagina-specifica\/"},"modified":"2020-09-06T15:56:07","modified_gmt":"2020-09-06T13:56:07","slug":"eseguire-una-query-solo-per-una-pagina-specifica","status":"publish","type":"topic","link":"https:\/\/it.wordpress.org\/support\/topic\/eseguire-una-query-solo-per-una-pagina-specifica\/","title":{"rendered":"Eseguire una query solo per una pagina specifica"},"content":{"rendered":"<p>Salve, ho questo semplice loop che stampa a video i titoli degli articoli contenuti nel post &#8220;news&#8221;.<br \/>\nHo inserito il codice nel file function.php del tema child di Asta.<br \/>\nIl codice per\u00f2 viene eseguito su tutte le pagine del sito, compreso il back office.<br \/>\nCome faccio a specificare che la query deve essere eseguita solo in una pagina specifica del sito?<br \/>\nGrazie per l&#8217;attenzione.<br \/>\n\/\/ The Query<br \/>\n$args = array(<br \/>\n\t&#8216;post_type&#8217; =&gt; &#8216;news&#8217;,<\/p>\n<p>);<br \/>\n$the_query = new WP_Query( $args );<\/p>\n<p>\/\/ The Loop<br \/>\nif ( $the_query-&gt;have_posts() ) {<br \/>\n    echo &#8216;<\/p>\n<ul>&#8216;;<br \/>\n    while ( $the_query-&gt;have_posts() ) {<br \/>\n        $the_query-&gt;the_post();<br \/>\n        echo &#8216;<\/p>\n<li>&#8216; . get_the_title() . &#8216;<\/li>\n<p>&#8216;;<br \/>\n    }<br \/>\n    echo &#8216;<\/ul>\n<p>&#8216;;<br \/>\n} else {<br \/>\n    echo &#8216;&lt;h1&gt;no posts found&lt;\/h1&gt;&#8217;;<br \/>\n}<br \/>\n\/* Restore original Post Data *\/<br \/>\nwp_reset_postdata();<\/p>\n","protected":false},"template":"","class_list":["post-12170695","topic","type-topic","status-publish","hentry","topic-tag-function-php","topic-tag-query"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/it.wordpress.org\/support\/wp-json\/wp\/v2\/topic\/12170695","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/it.wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/it.wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/it.wordpress.org\/support\/wp-json\/wp\/v2\/topic\/12170695\/revisions"}],"wp:attachment":[{"href":"https:\/\/it.wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=12170695"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}