[wp-trac] [WordPress Trac] #12898: Option in query_posts to include parent and/or grandparent categories

WordPress Trac wp-trac at lists.automattic.com
Wed Apr 7 15:52:27 UTC 2010


#12898: Option in query_posts to include parent and/or grandparent categories
-----------------------------+----------------------------------------------
 Reporter:  vlasky           |       Owner:  ryan                     
     Type:  feature request  |      Status:  new                      
 Priority:  normal           |   Milestone:  3.0                      
Component:  Query            |     Version:  3.0                      
 Severity:  normal           |    Keywords:  category, parent category
-----------------------------+----------------------------------------------
 When specifying a category or categores to retrieve posts from, there
 should be a query_posts() option to include the parent and or grandparent
 categories.

 This option could be called 'cat_levels', which would equal an integer
 number of levels to include.

 e.g.

 query_posts('cat=2'); would just retrieve posts in category id 2

 query_posts('cat=2&cat_levels=1') would retrieve posts in category id 2
 and posts in its parent category (if it exists)

 query_posts('cat=2&cat_levels=2') would retrieve all the above, plus the
 grandparent category (if it exists).

 One application for this feature is for geotargeting content. Let's say
 that you use the visitor IP address to detect that the person is from
 Germany, you can then make 'Germany' a child category of a  parent
 category 'European_Union'.

 This means that not only can you display posts related to Germany, but
 posts concerning European Union issues that may be relevant to a German
 visitor.

 Another request is an option to allow child categories to belong to
 multiple parents. This would be for the same reason. e.g. category
 'Germany' could belong to two parent categories - 'European_Union' and
 'German_Lanugage_Articles', which could then be searched to retrieve
 relevant posts via query_posts().

 If anyone has any neat workaround for the above, I would also be
 interested to see them.

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


More information about the wp-trac mailing list