对于一个名为“matches”的自定义Post类型,我创建了一个自定义permalink结构。结构显示方式正是我想要的,然而,我得到了404
每次我访问这个帖子。
我已尝试删除.htaccess
, 重新保存永久链接,刷新重写等等。这些都没有起到任何作用。
我使用的代码如下:
<?php
add_action( \'init\', array( $this, \'match_permalink_structure\' ) );
add_filter( \'post_type_link\', array( $this, \'better_match_permalinks\' ), 10, 3 );
function match_permalink_structure() {
global $wp_rewrite;
$structure = trailingslashit( __( \'match\', \'apollo\' ) );
$structure .= trailingslashit( \'%year%/%month%/%day%\' );
$structure .= trailingslashit( \'%matches%\' );
$wp_rewrite->add_rewrite_tag( "%matches%", \'([^/]+)\', "matches=" );
$wp_rewrite->add_permastruct( \'matches\', $structure, true );
}
function better_match_permalinks( $permalink, $post, $leavename ) {
$rewritecode = array(
\'%year%\',
\'%month%\',
\'%day%\',
$leavename ? \'\' : \'%matches%\',
);
$timestamp = get_field( \'match_datetime\', $post->ID );
if( ! empty( $timestamp ) ) {
$year = date( \'Y\', $timestamp );
$month = date( \'m\', $timestamp );
$day = date( \'d\', $timestamp );
} else {
$year = date( \'Y\', strtotime( $post->post_date ) );
$month = date( \'m\', strtotime( $post->post_date ) );
$day = date( \'d\', strtotime( $post->post_date ) );
}
$rewrite_replace = array(
$year,
$month,
$day,
$post->post_name,
);
$permalink = str_replace( $rewritecode, $rewrite_replace, $permalink );
return $permalink;
}
?>
我已安装
Rewrite Rules Inspector 这给了我以下匹配的信息:
wedstrijd/[0-9]{4}/%月%/[0-9]{1,2}/[^/]+/附件/([^/]+)/?$指数php?附件=$个匹配项1 匹配wedstrijd/[0-9]{4}/%month%/[0-9]{1,2}/[^/][+/附件/([^/][+)/trackback/?$指数php?附件=$个匹配项1&;tb=1匹配wedstrijd/[0-9]{4}/%month%/[0-9]{1,2}/[^/]+/附件/([^/]+)/提要/(提要| rdf | rss | rss2 | atom)/?$指数php?附件=$个匹配项1&;feed=$matches[2]matches wedstrijd/[0-9]{4}/%month%/[0-9]{1,2}/[^/][+/附件/([^/][+)/(feed | rdf | rss | rss2 | atom)/?$指数php?附件=$个匹配项1&;feed=$matches[2]matches wedstrijd/[0-9]{4}/%month%/[0-9]{1,2}/[^/][+/附件/([^/][+)/评论页-([0-9]{1,})/?$指数php?附件=$个匹配项1&;cpage=$个匹配项[2]个匹配项
我想这意味着%month%
大概我不确定。
有没有人知道我可能做错了什么,或者我需要做什么来解决这个问题?