{"id":4325718,"date":"2013-11-17T04:06:18","date_gmt":"2013-11-17T04:06:18","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/query_post-unsafe\/"},"modified":"2016-08-21T12:38:51","modified_gmt":"2016-08-21T12:38:51","slug":"query_post-unsafe","status":"closed","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/query_post-unsafe\/","title":{"rendered":"Query_post() &#8211; unsafe?"},"content":{"rendered":"<p>I would ask this on the Page Builder support site, but it is quite inactive and questions seem to be going unanswered. I think it&#8217;s a simple coding question so perhaps here will be fine.<\/p>\n<p>I&#8217;m using the &#8216;grid-loop&#8217; to display posts on pages. However, I&#8217;m creating multiple &#8216;grid-loop&#8217; files for each category, since a different category of posts will be displayed on their own respective page.<\/p>\n<p>For each new grid-loop file, I&#8217;m adding in <strong>query_posts( &#8216;cat=ID&#8217; );<\/strong> and using that to display the category I want. I&#8217;ve read that using these queries is unsafe or something? I&#8217;m using a different file for each category&#8217;s respective loop.<\/p>\n<p>Here&#8217;s the code for category 5&#8217;s loop.<\/p>\n<pre><code>&lt;?php\n\/**\n * Loop Name: Grid Child\n *\/\n?&gt;\n&lt;?php if( have_posts() ) : $i = 0; ?&gt;\n\n\t&lt;div class=&quot;vantage-grid-loop&quot;&gt;\n\t\t&lt;?php\n\t\tquery_posts( &#039;cat=5&#039; );\n\t\twhile( have_posts() ): the_post(); $i++ ?&gt;\n\t\t\t&lt;article &lt;?php post_class(array(&#039;grid-post&#039;)) ?&gt;&gt;\n\n\t\t\t\t&lt;?php if( has_post_thumbnail() ) : ?&gt;\n\t\t\t\t\t&lt;a class=&quot;grid-thumbnail&quot; href=&quot;&lt;?php the_permalink() ?&gt;&quot;&gt;\n\t\t\t\t\t\t&lt;?php the_post_thumbnail(&#039;vantage-grid-loop&#039;) ?&gt;\n\t\t\t\t\t&lt;\/a&gt;\n\t\t\t\t&lt;?php endif; ?&gt;\n\n\t\t\t\t&lt;h3&gt;&lt;a href=&quot;&lt;?php the_permalink() ?&gt;&quot;&gt;&lt;?php the_title() ?&gt;&lt;\/a&gt;&lt;\/h3&gt;\n\t\t\t\t&lt;div class=&quot;excerpt&quot;&gt;&lt;?php the_excerpt() ?&gt;&lt;\/div&gt;\n\t\t\t&lt;\/article&gt;\n\t\t\t&lt;?php if($i % 4 == 0) : ?&gt;&lt;div class=&quot;clear&quot;&gt;&lt;\/div&gt;&lt;?php endif; ?&gt;\n\t\t&lt;?php endwhile; ?&gt;\n\t&lt;\/div&gt;\n\n\t&lt;?php vantage_content_nav( &#039;nav-below&#039; ); ?&gt;\n\n&lt;?php endif; ?&gt;<\/code><\/pre>\n<p>The query is near the top. Will I have any problems with it? It seems to be doing exactly what I want, and I suck at anything coding related so it&#8217;s the best I can do.<\/p>\n","protected":false},"template":"","class_list":["post-4325718","topic","type-topic","status-closed","hentry"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/4325718","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\/4325718\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=4325718"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}