在自定义帖子类型存档的开头,我添加了以下代码:
<?php
if (!is_date()) { // redirect mycpt archive page to the most recent post date page
wp_safe_redirect(seron_get_most_recent_mycpt_link());
exit;
}
?>
A还将此函数添加到函数中。php文件:
/**
* Genrate a URL for the most recent mycpt post date.
*/
function seron_get_most_recent_mycpt_link() {
$latest_post = get_posts(array(\'numberposts\' => 1,
\'orderby\' => \'post_date\',
\'order\' => \'DESC\',
\'post_type\' => \'mycpt\')
);
$date = explode(\' \', $latest_post[0]->post_date);
return home_url() . \'/mycpt/\' . str_replace(\'-\', \'/\', $date[0]);
}