{"id":58682,"date":"2013-10-24T10:16:14","date_gmt":"2013-10-24T08:16:14","guid":{"rendered":"https:\/\/nl.wordpress.org\/support\/topic\/query-code-zorgt-voor-exhausted-memory-al-bij-11-posts\/"},"modified":"2016-08-05T01:13:22","modified_gmt":"2016-08-05T01:13:22","slug":"query-code-zorgt-voor-exhausted-memory-al-bij-11-posts","status":"closed","type":"topic","link":"https:\/\/nl.wordpress.org\/support\/topic\/query-code-zorgt-voor-exhausted-memory-al-bij-11-posts\/","title":{"rendered":"Query code zorgt voor &#039;exhausted memory&#039; al bij 11 posts"},"content":{"rendered":"<p>Voor mijn website heb ik een vrij ingewikkelde Query code(zie onder) nodig. Alles werkte naar behoren tot het installeren van de WPML plugin (kan toeval zijn). Nu krijg ik op mijn &#8220;product&#8221; pagina in een categorie waar 11 posts zijn al de melding:<\/p>\n<blockquote>\n<p>Allowed memory size of 134217728 bytes exhausted (tried to allocate 523800 bytes) in &#8230;&#8230;&#8230;.\/wp-includes\/cache.php on line 113\n<\/p>\n<\/blockquote>\n<p>Pagina&#8217;s met minder posts (en zelfde code) geven geen problemen.<\/p>\n<p>Ik heb de volgende stappen al ondernomen:<\/p>\n<p>Toegevoegd aan wp-config: define(&#8216;WP_MEMORY_LIMIT&#8217;, &#8217;96M&#8217;);(hoger bijvoorbeeld 256m werkt niet en in firefox krijg ik een melding over een server reset oid)<br \/>\nDeactiveren van alle plugins werkt ook niet<\/p>\n<p>Op de indexpagina, waar grotendeels dezelfde code stond (laat alleen max 3 posts zien) heb ik deze in een aparte php file gezet en geinclude. Daar is het probleem wel opgelost.<\/p>\n<p>Het weghalen van de betreffende code lost het probleem ook op.<br \/>\nIk ben geen php programmeur en was al heel trots zo ver gekomen te zijn. Nu loop ik toch vast.<\/p>\n<p>Het betreffende probleem zit hem in onderstaande code, wie kan hier naar kijken?<\/p>\n<pre><code>&lt;?php\nif (is_category( )) {\n  $cat = get_query_var(&#039;cat&#039;);\n  $category = get_term_by(&#039;id&#039;,$cat, &#039;category&#039;);\n  if ($category) {\n    $args=array(\n      &#039;category__in&#039; =&gt; array($category-&gt;term_id),\n      &#039;post_type&#039; =&gt; &#039;product&#039;\n      );\n    $my_query = null;\n    $my_query = new WP_Query($args);\n    if( $my_query-&gt;have_posts() ) {\n\n      while ($my_query-&gt;have_posts()) : $my_query-&gt;the_post(); ?&gt;\n\n        &lt;div id=&quot;product-preview&quot;&gt;&lt;?php if (in_category(&#039;tweedehands&#039;)) { ?&gt;&lt;img src=&quot;&lt;?php bloginfo(&#039;template_directory&#039;); ?&gt;\/images\/icons\/tiny-icon-occasions.png&quot; class=&quot;occasion&quot; title=&quot;occasion&quot; alt=&quot;occasion&quot; &gt;\n\t\t\t\t\t\t\t&lt;?php } ?&gt;\n                     &lt;a href=&quot;&lt;?php the_permalink() ?&gt;&quot;&gt;&lt;p class=&quot;product-name&quot;&gt;&lt;?php the_title(); ?&gt;&lt;\/p&gt;&lt;\/a&gt;\n                    \t&lt;div class=&quot;news-post_img&quot;&gt;\n                               &lt;a href=&quot;&lt;?php the_permalink() ?&gt;&quot;&gt;&lt;?php if ( has_post_thumbnail()) : ?&gt;\n\n   &lt;?php the_post_thumbnail(&#039;thumbnail&#039;) ?&gt;\n\n   &lt;\/a&gt;\n\n &lt;?php endif; ?&gt;\n\n\t\t\t\t\t\t&lt;\/div&gt;\n\n                        &lt;div id=&quot;preview&quot;&gt;\n                    \t&lt;p&gt;&lt;?php\n                the_terms( $post-&gt;ID, &#039;merk&#039; ,  &#039;Merk(en): &#039; );\n                    ?&gt;&lt;\/p&gt;\n                    \t&lt;p&gt;Categorie(\u00ebn):&lt;br \/&gt; &lt;?php\n$categories = get_the_category();\n$separator = &#039; &#039;;\n$output = &#039;&#039;;\nif($categories){\n\tforeach($categories as $category) {\n\t\t$output .= &#039;&lt;a href=&quot;&#039;.get_category_link( $category-&gt;term_id ).&#039;&quot; title=&quot;&#039; . esc_attr( sprintf( __( &quot;View all posts in %s&quot; ), $category-&gt;name ) ) . &#039;&quot;&gt;&#039;.$category-&gt;cat_name.&#039;&lt;\/a&gt;&lt;br&gt;&#039;.$separator;\n\t}\necho trim($output, $separator);\n}\n?&gt;&lt;\/p&gt;\n      &lt;\/div&gt;\n      &lt;a href=&quot;&lt;?php the_permalink() ?&gt;&quot;&gt;&lt;img src=&quot;&lt;?php bloginfo(&#039;template_directory&#039;); ?&gt;\/images\/bullet.png&quot; class=&quot;floatRight&quot; title=&quot;&quot; alt=&quot;more&quot; &gt; &lt;\/a&gt;\n       &lt;\/div&gt;\n       &lt;?php\n      endwhile;\n    }\n  wp_reset_query();  \/\/ Restore global post data stomped by the_post().\n  }\n}\n?&gt;<\/code><\/pre>\n","protected":false},"template":"","class_list":["post-58682","topic","type-topic","status-closed","hentry","topic-tag-allowed-memory-size","topic-tag-custom-post-type","topic-tag-exhausted","topic-tag-memory","topic-tag-query"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/nl.wordpress.org\/support\/wp-json\/wp\/v2\/topic\/58682","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nl.wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/nl.wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/nl.wordpress.org\/support\/wp-json\/wp\/v2\/topic\/58682\/revisions"}],"wp:attachment":[{"href":"https:\/\/nl.wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=58682"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}