{"id":4515223,"date":"2014-01-17T18:16:39","date_gmt":"2014-01-17T18:16:39","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/wp_query-priority-ordering\/"},"modified":"2016-08-21T14:52:47","modified_gmt":"2016-08-21T14:52:47","slug":"wp_query-priority-ordering","status":"closed","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/wp_query-priority-ordering\/","title":{"rendered":"WP_Query Priority Ordering"},"content":{"rendered":"<p>Hi WordPress,<\/p>\n<p>I was hoping to get some help with a custom query I am writing for a gallery system on my site.<\/p>\n<p>The problem is, my content is split across multiple post types, and while my query is pulling in all the content fine, one of my post types has nearly 1,000 entries. <\/p>\n<p>Therefore, the query is returning hundreds of entries from the one post type before it happens to return one from another post type which has relatively few entries (10-30).<\/p>\n<p>So, is there a way to keep the results orderby &#8220;random&#8221; but prioritise (or better yet deprioritise) the actual post_types so that the less populated post_types appear closer to the start of the query results?<\/p>\n<p>My query is written below (disregard the $filter variable &#8212; I have also implemented a filter system):<\/p>\n<pre><code>$paged = (get_query_var(&#039;paged&#039;)) ? get_query_var(&#039;paged&#039;) : 1;\n$filter = esc_sql($_GET[&#039;filter&#039;]);\n$pts = array(&#039;pt1&#039;,&#039;pt2&#039;,&#039;pt3&#039;,&#039;pt4&#039;);\nif(!in_array($filter, $cats)) $filter = $cats;\n$args = array(&#039;post_type&#039;\t=&gt; $filter,\n\t      &#039;posts_per_page&#039;\t=&gt; 8,\n\t      &#039;paged&#039;\t\t=&gt; $paged,\n\t      &#039;orderby&#039;\t\t=&gt; &#039;post_type rand&#039;,\n\t      &#039;post_status&#039;\t=&gt; &#039;publish&#039;);\n$the_query = new WP_Query;\n$the_query-&gt;query($args);<\/code><\/pre>\n<p>I have changed the variable names\/custom post type names.<\/p>\n<p>Thanks for any help you can provide.<\/p>\n<p>Regards,<br \/>\nGenericBox<\/p>\n","protected":false},"template":"","class_list":["post-4515223","topic","type-topic","status-closed","hentry"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/4515223","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\/4515223\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=4515223"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}