我想你现在的问题是,当你使用自定义帖子类型时,WordPress没有触及它的内置标签,如date和postname。尝试使用以下代码here:
/ Add filter to plugin init function
add_filter(\'post_type_link\', \'translate_permalink\', 10, 3);
// Adapted from get_permalink function in wp-includes/link-template.php
function translate_permalink($permalink, $post_id, $leavename) {
$post = get_post($post_id);
$rewritecode = array(
\'%year%\',
\'%monthnum%\',
\'%day%\',
\'%hour%\',
\'%minute%\',
\'%second%\',
$leavename? \'\' : \'%postname%\',
\'%post_id%\',
\'%category%\',
\'%author%\',
$leavename? \'\' : \'%pagename%\',
);
if ( \'\' != $permalink && !in_array($post->post_status, array(\'draft\', \'pending\', \'auto-draft\')) ) {
$unixtime = strtotime($post->post_date);
$category = \'\';
if ( strpos($permalink, \'%category%\') !== false ) {
$cats = get_the_category($post->ID);
if ( $cats ) {
usort($cats, \'_usort_terms_by_ID\'); // order by ID
$category = $cats[0]->slug;
if ( $parent = $cats[0]->parent )
$category = get_category_parents($parent, false, \'/\', true) . $category;
}
// show default category in permalinks, without
// having to assign it explicitly
if ( empty($category) ) {
$default_category = get_category( get_option( \'default_category\' ) );
$category = is_wp_error( $default_category ) ? \'\' : $default_category->slug;
}
}
$author = \'\';
if ( strpos($permalink, \'%author%\') !== false ) {
$authordata = get_userdata($post->post_author);
$author = $authordata->user_nicename;
}
$date = explode(" ",date(\'Y m d H i s\', $unixtime));
$rewritereplace =
array(
$date[0],
$date[1],
$date[2],
$date[3],
$date[4],
$date[5],
$post->post_name,
$post->ID,
$category,
$author,
$post->post_name,
);
$permalink = str_replace($rewritecode, $rewritereplace, $permalink);
} else { // if they\'re not using the fancy permalink option
}
return $permalink;
}
这是一个过滤器,通常是内置的,在处理帖子时会调用到Wordpress中,但不会调用自定义帖子类型。基本上,它处理与永久链接一起使用的标记。此代码应该允许您使用CPT的日期。