Redirecting category archive to first child post available

Posted in: Newspaper
Post count: 13

Is it possible to redirect category archive page to first available child post?

Post count: 13

actually, I tried this as suggested on stackoverflow but I guess newspaper works in different way, It didn’t work.

// use template_redirect action:
add_action( ‘template_redirect’, ‘my_redirect_to_post’ );

/// Function to redirect from certain category pages to first post of those categories
function my_redirect_to_post() {
if (is_category(‘3’) || is_category(‘5’) ) {
$category = get_the_category();
$posts = query_posts(‘showposts=1&cat=’.$category[0]->cat_ID);
if(have_posts()) :
wp_redirect(get_permalink($post->ID));
endif;
}
}

Post count: 22421

Hello dragon,

The easiest way to do it is to use a redirect plugin. something like https://wordpress.org/plugins/simple-301-redirects/

Thank you!

Viewing 3 posts - 1 through 3 (of 3 total)
The forum ‘Newspaper’ is closed to new topics and replies.