Hi!
I am trying to redirect a page to the latest post in a particular category.
I found a redirect code from somewhere which redirects to URL mentioned in the body of the post but I can't figure out how to modify it redirect to the latest post in a particular category.
<?php
/*
Template Name: Redirect
*/
if (have_posts()) {
the_post();
$pattern = '@(https?://([-\w\.]+)+(:\d+)?(/([\w/_\.]*(\?\S+)?)?)?)@';
preg_match($pattern, get_the_excerpt(), $matches);
if ($matches[0]) header('Location: '.$matches[0]);
else echo 'Enter a URL into your page body text.';
}
?>