[wp-hackers] 1 taxonomy on 2 different custom post types

Aero Maxx aero.maxx.d at gmail.com
Mon Aug 20 07:55:45 UTC 2012

On 19/08/2012 01:20, Mike Schinkel wrote:
> On Aug 18, 2012, at 2:25 PM, Aero Maxx wrote:
>> Is it at all possible to have 1 custom taxonomy on 2 different custom post types, and have them filtered.
>> I have 2 different custom post types that both use the same taxonomy, and I would like to do url filtering.
>> One is called "Draw Results" and the other "Ball Statistics", I would like the below urls so show only posts in the custom post type in the url that are in the taxonomy "Game".
>> http://www.domain.com/draw-results/game/lotto
>> http://www.domain.com/ball-statistics/game/lotto
>> This was working when was only 1 custom post type, but since I have added a 2nd the above links dont filter, they show all posts in the taxonomy regardless of which custom post type they are in.
> Your might be able to use add_rewrite_rule() although it may conflict with other URLs, not sure. I rarely use the "official" approach because it requires rewrite rules to be refreshed.
> What I like to use is the 'parse_request' hook at modify $wp->query_args.  You can find an example that should meeting your needs here and it can give you a little insight into what URLs translate to internally:
> https://gist.github.com/3390496
> -Mike
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
Thanks for this, I gave it a try...

I did a var_dump on $wp->query_vars outside of the if statement in the 
function you wrote and this is the result.

Notice: Undefined offset: 3 in ... 
/public/wordpress/wp-content/themes/twentyeleven-child/functions.php on 
line 472 - (This is line 472: 'game' => $matches[3])
array(2) { ["post_type"]=> string(12) "draw-results" ["game"]=> NULL }

array(1) { ["attachment"]=> string(5) "lotto" }


More information about the wp-hackers mailing list