<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><style type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; }
#msg ul, pre { overflow: auto; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<title>[13838] trunk/wp-includes/query.php:
  Support multiple post_type query params/post_type'
 s to be specified in a query.</title>
</head>
<body>

<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/13838">13838</a></dd>
<dt>Author</dt> <dd>dd32</dd>
<dt>Date</dt> <dd>2010-03-27 05:56:27 +0000 (Sat, 27 Mar 2010)</dd>
</dl>

<h3>Log Message</h3>
<pre>Support multiple post_type query params/post_type's to be specified in a query. See <a href="http://trac.wordpress.org/ticket/12704">#12704</a></pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpincludesqueryphp">trunk/wp-includes/query.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpincludesqueryphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/query.php (13837 => 13838)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/query.php        2010-03-27 05:42:08 UTC (rev 13837)
+++ trunk/wp-includes/query.php        2010-03-27 05:56:27 UTC (rev 13838)
</span><span class="lines">@@ -1712,31 +1712,49 @@
</span><span class="cx">                 if ( $q['day'] )
</span><span class="cx">                         $where .= &quot; AND DAYOFMONTH($wpdb-&gt;posts.post_date)='&quot; . $q['day'] . &quot;'&quot;;
</span><span class="cx"> 
</span><del>-                if ( !empty($q['post_type']) &amp;&amp; !empty($q[ $q['post_type'] ]) ) {
-                        $q[ $q['post_type'] ] = str_replace('%2F', '/', urlencode(urldecode($q[ $q['post_type'] ])));
-                        $post_type_object = get_post_type_object($q['post_type']);
-                        if ( ! $post_type_object-&gt;hierarchical || strpos($q[ $q['post_type'] ], '/') === false) {
-                                $q['name'] = $q[ $q['post_type'] ] = sanitize_title($q[ $q['post_type'] ]);
-                                $where .= &quot; AND $wpdb-&gt;posts.post_name = '&quot; . $q[ $q['post_type'] ] . &quot;'&quot;;
-                        } else {
-                                // Hierarchical post type, need to look deeper to see if its an attachment or this post_type
-                                if ( isset($this-&gt;queried_object_id) ) {
-                                        $reqpage = $this-&gt;queried_object_id;
</del><ins>+                if ( !empty($q['post_type']) ) {
+                        $_pt = is_array($q['post_type']) ? $q['post_type'] : array($q['post_type']);
+                        foreach ( $_pt as $_post_type ) {
+                                if ( empty($q[ $_post_type ]) )
+                                        continue;
+
+                                $q[ $_post_type ] = str_replace('%2F', '/', urlencode(urldecode($q[ $_post_type ])));
+                                $post_type_object = get_post_type_object($_post_type);
+                                if ( ! $post_type_object-&gt;hierarchical || strpos($q[ $_post_type ], '/') === false) {
+                                        $q['name'] = $q[ $_post_type ] = sanitize_title($q[ $_post_type ]);
+                                        $_names[] = $q[ $_post_type ];
</ins><span class="cx">                                 } else {
</span><del>-                                        $reqpage = get_page_by_path($q[ $q['post_type'] ], OBJECT, $q['post_type']);
-                                        if ( !empty($reqpage) )
-                                                $reqpage = $reqpage-&gt;ID;
-                                        else
-                                                $reqpage = 0;
</del><ins>+                                        // Hierarchical post type, need to look deeper to see if its an attachment or this post_type
+                                        if ( isset($this-&gt;queried_object_id) ) {
+                                                $reqpage = $this-&gt;queried_object_id;
+                                        } else {
+                                                $reqpage = get_page_by_path($q[ $_post_type ], OBJECT, $_post_type);
+                                                if ( !empty($reqpage) )
+                                                        $reqpage = $reqpage-&gt;ID;
+                                                else
+                                                        $reqpage = 0;
+                                        }
+                                        $_ids[] = $reqpage;
+                                        $reqpage_obj = get_page($reqpage);
+                                        if ( is_object($reqpage_obj) &amp;&amp; 'attachment' == $reqpage_obj-&gt;post_type ) {
+                                                $this-&gt;is_attachment = true;
+                                                $q['attachment_id'] = $reqpage;
+                                                $post_type = $q['post_type'] = 'attachment';
+                                        }
</ins><span class="cx">                                 }
</span><del>-                                $where .= &quot; AND ($wpdb-&gt;posts.ID = '$reqpage')&quot;;
-                                $reqpage_obj = get_page($reqpage);
-                                if ( is_object($reqpage_obj) &amp;&amp; 'attachment' == $reqpage_obj-&gt;post_type ) {
-                                        $this-&gt;is_attachment = true;
-                                        $q['attachment_id'] = $reqpage;
-                                        $post_type = $q['post_type'] = 'attachment';
</del><ins>+                        } //end foreach
+
+                        if ( !empty($_names) || !empty($_ids) ) {
+                                $where .= ' AND (1=0';
+                                if ( !empty($_names) )
+                                        $where .= &quot; OR $wpdb-&gt;posts.post_name IN('&quot; . implode(&quot;', '&quot;, $_names) . &quot;')&quot;;
+                                if ( !empty($_ids) ) {
+                                        $_ids = array_map('absint', $_ids);
+                                        $where .= &quot; OR $wpdb-&gt;posts.ID IN(&quot; . implode(',', $_ids) . &quot;)&quot;;
</ins><span class="cx">                                 }
</span><ins>+                                $where .= ')';
</ins><span class="cx">                         }
</span><ins>+                        unset($_ids, $_names, $_pt, $_post_type);
</ins><span class="cx">                 } elseif ( '' != $q['name'] ) {
</span><span class="cx">                         $q['name'] = sanitize_title($q['name']);
</span><span class="cx">                         $where .= &quot; AND $wpdb-&gt;posts.post_name = '&quot; . $q['name'] . &quot;'&quot;;
</span><span class="lines">@@ -2373,7 +2391,7 @@
</span><span class="cx">                 $this-&gt;request = &quot; SELECT $found_rows $distinct $fields FROM $wpdb-&gt;posts $join WHERE 1=1 $where $groupby $orderby $limits&quot;;
</span><span class="cx">                 if ( !$q['suppress_filters'] )
</span><span class="cx">                         $this-&gt;request = apply_filters_ref_array('posts_request', array( $this-&gt;request, &amp;$this ) );
</span><del>-
</del><ins>+var_Dump($this-&gt;request);
</ins><span class="cx">                 $this-&gt;posts = $wpdb-&gt;get_results($this-&gt;request);
</span><span class="cx">                 // Raw results filter.  Prior to status checks.
</span><span class="cx">                 if ( !$q['suppress_filters'] )
</span><span class="lines">@@ -2832,4 +2850,4 @@
</span><span class="cx"> 
</span><span class="cx">         return true;
</span><span class="cx"> }
</span><del>-?&gt;
</del><ins>+?&gt;
</ins><span class="cx">\ No newline at end of file
</span></span></pre>
</div>
</div>

</body>
</html>