[wp-trac] [WordPress Trac] #22556: A taxonomy archive query for attachments can't return results

WordPress Trac noreply at wordpress.org
Fri Nov 23 15:11:51 UTC 2012


#22556: A taxonomy archive query for attachments can't return results
-----------------------------+--------------------------
 Reporter:  ocean90          |       Type:  defect (bug)
   Status:  new              |   Priority:  normal
Milestone:  Awaiting Review  |  Component:  Query
  Version:                   |   Severity:  normal
 Keywords:                   |
-----------------------------+--------------------------
 In #21391 we made it easier to use custom taxonomies for attachments.

 Example:
 {{{
 function ds_register_attachment_taxonomies() {
         $args = array(
                 'label' => 'Color',
         );

         register_taxonomy(
                 'image-color',
                 'attachment:image',
                 $args
         );
 }
 add_action( 'init', 'ds_register_attachment_taxonomies' );
 }}}

 This makes it also possible to make a query for this specific taxonomy.
 Example: 5 images has the term "red". The query: !http://example.com
 /image-color/red/

 But: The page returns no attachments.

 The query:
 {{{
 SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts INNER JOIN
 wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id)
 WHERE 1=1 AND ( wp_term_relationships.term_taxonomy_id IN (404) ) AND
 wp_posts.post_type IN ('attachment') AND (wp_posts.post_status = 'publish'
 OR wp_posts.post_status = 'private') GROUP BY wp_posts.ID ORDER BY
 wp_posts.post_date DESC LIMIT 0, 1
 }}}

 The problem is the `AND (wp_posts.post_status = 'publish' OR
 wp_posts.post_status = 'private')` part. Attachments post status is
 inherit, therefore no results.

 The attached patch checks if the current post type is `attachment` and
 sets the post_status to `inherit`.

 I would like to get this in 3.5, since it's one of the new features and
 could be really annoying,

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/22556>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list