• My website that sells individual products on Post pages. The products have a life span of about 12 months, after which point they need to be removed and a fresh set of products implemented. The newly implemented Posts have new URLs and there are too many to redirect individual products to their (new) closest match.

    On my 404 error page template, I am currently using the Simple Redirect for WordPress from Chris Carey below to 301 redirect the deleted products to the homepage of the website. This works great, but I’d like to extend it to another level.

    //Simple Redirect for WordPress.
    //Christopher Carey
    //301 Redirect for WordPress
    //http://wwww.noheat.com
    
    header("HTTP/1.1 301 Moved Permanently");
    header("Location: ".get_bloginfo('url'));
    exit();
    
    ?>

    What I would like to do is extend this code to:

    • Detect the product’s assigned category
    • Redirect to the product’s respective assigned category instead of the homepage

    There wasn’t much in Google or here within the forum that I could find to support what I’m looking to accomplish, but does something like this already exist?

    I don’t think the code would be terribly difficult to write, but I’m not a programmer & can’t get the syntax correct.

    Here’s kinda what I think it will resemble, in addition to some parts from the code above:

    <?php
    $category = get_the_category();
    $category_id = $category[0]->cat_ID;
    $relocate = get_category_link($category_id);
    header("Location:".$relocate);
    ?>

    If you can help I’d certainly appreciate it.

    [ Please do not bump, it’s not permitted here. ]

  • The topic ‘Redirect Deleted Posts to Assigned Category’ is closed to new replies.