[wp-hackers] Rewrite rules for combined category and custom taxonomies

wjm 776a6d at gmail.com
Sun May 16 18:57:08 UTC 2010


Mark,
that was exactly what i was looking for.
Thanks a lot for the fast and precise response.

This is the coded I added to the plugin file to disable cannonical
I am adding it so other people can make use of this.

add_action( 'template_redirect', 'rr_disable_canonical', 9);

function rr_disable_canonical() {

$category_name = get_query_var( 'category_name' );

if ( cat_is_ancestor_of( CHILDTHEME_CAT_ID_ESPECIALIDAD,
> get_cat_ID($category_name) ) ) {

$taxonomy = get_query_var( 'taxonomy' );

$taxonomy_term = get_query_var( 'term' );

$especialidad_informacion = get_query_var( 'especialidad_informacion' );

if ( !empty($especialidad_informacion) ||  ( !empty($taxonomy) &&
> !empty($taxonomy_term) ) ) {

remove_action('template_redirect', 'redirect_canonical');

}

}

return;

}


CHILDTHEME_CAT_ID_ESPECIALIDAD is the ID for the "especialidad" category.

Thanks again,
I dont feel frustrated anymore.
:D
- wjm

2010/5/16 Mark Jaquith <markjaquith at gmail.com>

> On Sun, May 16, 2010 at 1:49 PM, wjm <776a6d at gmail.com> wrote:
> > Instead of staying in: */especialidad/enfermeria/especialidad-cursos/*
> > I keep getting redirected to: */info/especialidad/enfermeria/*
> > (*info* is the *category base*).
>
> It is likely the canonical redirect functionality that is doing that.
> Your rewrite rule makes WordPress think it is a category query. You
> can hook in to the 'redirect_canonical' filter to conditionally
> disable this redirect.
>
> Here is how it is called.
>
> > $redirect_url = apply_filters('redirect_canonical', $redirect_url,
> $requested_url);
>
> If you pass back FALSE, it will cancel the redirect.
>
> If you hook in before template_redirect is fired, you could also
> conditionally disable the canonical redirect code. Might be more
> efficient.
>
> This is how it is called:
>
> > add_action('template_redirect', 'redirect_canonical');
>
> Some test like this could be used to trigger the override:
> get_query_var( 'taxonomy' ) == 'especialidad_informacion' &&
> get_query_var( 'category_name' )
>
> --
> Mark Jaquith
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>


More information about the wp-hackers mailing list