[wp-trac] [WordPress Trac] #18858: Would like to see a function similar to get_objects_in_term that filters by post_type.

WordPress Trac wp-trac at lists.automattic.com
Fri Oct 7 19:21:20 UTC 2011


#18858: Would like to see a function similar to get_objects_in_term that filters by
post_type.
-----------------------------------------+------------------------------
 Reporter:  sqlwiz                       |       Owner:
     Type:  enhancement                  |      Status:  new
 Priority:  normal                       |   Milestone:  Awaiting Review
Component:  Taxonomy                     |     Version:  3.1.4
 Severity:  normal                       |  Resolution:
 Keywords:  has-patch reporter-feedback  |
-----------------------------------------+------------------------------

Comment (by sqlwiz):

 @mikeschinkel - Hope this isn't too long winded...

 You can see an example of the type of problem I'm trying to solve in the
 standard WP Admin screens. Category, Post Tag and custom taxonomy
 management pages contain the following fields in the sidebar list table:

 Name, Description, Slug and Posts

 The Posts field is a hyperlinked count of the total number of posts of all
 post types, yet if you click on the link, you get only the posts of the
 current post type.

 For example, let's say there are two post types "Posts" and "Interviews"
 and the post tags are used on both types.

 ||Post||Post Type||Post Tag||
 ||1||post||"key"||
 ||2||post||"important"||
 ||3||interview||"key"||

 If you look at Post Tags for "Posts", you see:

 ||Name||Description||Slug||Posts||
 ||key|| ||key||2||
 ||important|| ||important||1||

 If you click on the "2" for key, you'll see a list of "Posts" type posts,
 there will be only one post on the list. Worse still is what happens in
 "Interviews". If you click on the "1" for important, you'll get an empty
 list. Of course, this could be fixed by replacing the count with the words
 'show posts'.

 I run into the same issue at times - unwanted object ids returned - when
 using get_objects_in_term(). I have to loop thru the array and examine
 each returned object_id with get_post_type. It would be more efficient to
 deal with this in the DB when hundreds of objects are returned.

 A function like get_post_type_objects_in_term would return an array of one
 object id for the term "key" (assuming $term_id is the id).

 get_post_type_objects_in_term($term_id, 'post', 'post_tag')

 I am using this with custom post_types and custom taxonomies on a number
 of sites.

 @scribu -

 Love tax_query - use it all the time. This is more of a convenience
 wrapper for themers that are more designers than developers and find
 wp_query a chore to use over and over.

 In fact, we are doing post to post links - using taxomony - creating
 master-detail relationships and all we want at times is a field from the
 master or the master's meta. A simple function call is much more
 maintainable.

 I am aware of the post 2 post plugin - and the design change you made from
 taxonomy to custom table - as well as the ongoing improvements to the
 plugin. It looks really promising for those using WP as a CMS. We would
 use it if it became part of core. Until then, we'll try make do.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/18858#comment:4>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list