Linking to the most recent post in my podcast category
I am attempting to pulloff what the author did here: How can I link to the most recent post in a category?
However, after updating my functions.php file in my child theme I can not get it to load the latest post from the podcast category. When I try:
http://talkdirtytome.show/podcast/?latest
it returns with a list off all the podcast episodes in the podcast category. When I attempt to goto http://talkdirtytome.show/category/podcast/?latest
I get a Nothing Found page. I am sure there has got to be something simple I am missing I just dont know what it is. Any help would be greatly appreciated!
The code currently in my functions.php file is:
function wpa_latest_in_category_redirect( $request ){
if( isset( $_GET['latest'] )
isset( $request-query_vars['category_name'] ) ){
$latest = new WP_Query( array(
'category_name' = $request-query_vars['category_name'],
'posts_per_page' = 1
) );
if( $latest-have_posts() ){
wp_redirect( get_permalink( $latest-post-ID ) );
exit;
}
}
}
add_action( 'parse_request', 'wpa_latest_in_category_redirect' );
Topic recent-posts link-category categories Wordpress
Category Web