1

Two similar custom post types have been created by my theme and a plugin I'm using. These basically customizing the categories post type. They are as follows:

  1. product-category
  2. listing-category

I am trying to do a default redirect, concatinating the appropriate same category name (fitness) but using number 2 (listing-category) rather than number 1 (product-category) on all links.

Example 1: thesite . com/product-category/fitness/

redirect all of these links to thesite . com/listing-category/fitness/


Example 2: thesite . com/product-category/food/

redirect all of these links to thesite . com/listing-category/food/

I amending the following code from another post. Any ideas how to make this work? Sincerely appreciate it!

/** * Redirect 'product-category/fitness/' category to 'listing-category/fitness/' ( example: http:// thesite . com/listing-category/fitness/' ) * */


add_filter('template_redirect', 'j66_template_redirect_filter', 10, 3); function j66_template_redirect_filter( $url, $term, $taxonomy ) {

if ( is_post_type_archive( 'product-category' ) ) {

    $url = site_url( 'listing-category/' );

    wp_safe_redirect( $url, 301 );

    exit;

}

return $url;

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.