{"id":111132,"date":"2021-07-01T14:38:49","date_gmt":"2021-07-01T12:38:49","guid":{"rendered":"https:\/\/de.wordpress.org\/support\/topic\/custom-theme-fatal-error-in-loop\/"},"modified":"2021-07-01T14:38:49","modified_gmt":"2021-07-01T12:38:49","slug":"custom-theme-fatal-error-in-loop","status":"publish","type":"topic","link":"https:\/\/de.wordpress.org\/support\/topic\/custom-theme-fatal-error-in-loop\/","title":{"rendered":"Custom Theme: Fatal Error in Loop"},"content":{"rendered":"<p>Ich bin WP Anf\u00e4nger und habe versucht custom querys zu machen um zB Pages statt Posts anzuzeigen.<\/p>\n<pre><code>&lt;div id=&quot;content&quot;&gt;\n &lt;?php \n   $filter = array(\n    &#039;post_type&#039; =&gt; &#039;page&#039;,\n   );\n\t$pages = new WP_Query($filter);\n\tif($pages-&gt;have_posts()){\n    while($pages-&gt;have_posts()){ \n        $pages-&gt;the_post(); \n        ?&gt;&lt;h1&gt; &lt;?php the_title();?&gt; &lt;\/h1&gt; \n        &lt;?php\n    }\n\t}else{\n\t\techo &quot;No Pages&quot;;\n\t}\n    ?&gt;\n&lt;\/div&gt;<\/code><\/pre>\n<p>Wenn ich die Seite aufrufe wird der Titel EINER Seite angezeigt.<br \/>\nBei der zweiten Iteration des Loops kommt eine Kritische Fehlermeldung<br \/>\nFatal error: Call to a member function have_posts() &#8230;<\/p>\n<p>Was mach ich falsch?<\/p>\n","protected":false},"template":"","class_list":["post-111132","topic","type-topic","status-publish","hentry","topic-tag-loop","topic-tag-wp_query"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/de.wordpress.org\/support\/wp-json\/wp\/v2\/topic\/111132","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/de.wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/de.wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/de.wordpress.org\/support\/wp-json\/wp\/v2\/topic\/111132\/revisions"}],"wp:attachment":[{"href":"https:\/\/de.wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=111132"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}