听起来你离这里很近了,你唯一剩下的问题是你对流派和电影的永久链接发生了冲突。
\'movies\' CPT permalink
/genres/%custom field meta box value%/%movie%/
\'genres\' CPT permalink
/genres/%genre%/
这里的问题是使用
add_permastruct
. 当它为电影制定规则时,它们看起来是这样的:
genres/([^/]+)/([^/]+)(/[0-9]+)?/?$
=> index.php?genre=$matches[1]&movies=$matches[2]&page=$matches[3]
按照WordPress处理请求的方式,您不能在同一URL中设置多个帖子类型——WordPress在第一个帖子类型之后停止。也就是说,
they can be in the pretty URL, but not in the "ugly" one that generates the request and query. 任何重写规则
movies=
不能包含
genre=
. 以下是对
rb_add_rewrite_rules
. 您可以提取任何可能不需要的规则,如附件URL、提要URL等。与往常一样,在进行重写更改时,请确保通过转到“设置”->“永久链接”并单击“保存更改”刷新永久链接。另外,确保
\'rewrite\' => false
在两种自定义帖子类型上都设置。
function rb_add_rewrite_rules() {
add_rewrite_rule( \'genres/[^/]+/[^/]+/attachment/([^/]+)/?$\', \'index.php?attachment=$matches[1]\', \'top\' );
add_rewrite_rule( \'genres/[^/]+/[^/]+/attachment/([^/]+)/trackback/?$\', \'index.php?attachment=$matches[1]&tb=1\', \'top\' );
add_rewrite_rule( \'genres/[^/]+/[^/]+/attachment/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$\', \'index.php?attachment=$matches[1]&feed=$matches[2]\', \'top\' );
add_rewrite_rule( \'genres/[^/]+/[^/]+/attachment/([^/]+)/(feed|rdf|rss|rss2|atom)/?$\', \'index.php?attachment=$matches[1]&feed=$matches[2]\', \'top\' );
add_rewrite_rule( \'genres/[^/]+/[^/]+/attachment/([^/]+)/comment-page-([0-9]{1,})/?$\', \'index.php?attachment=$matches[1]&cpage=$matches[2]\', \'top\' );
add_rewrite_rule( \'genres/[^/]+/([^/]+)/trackback/?$\', \'index.php?movies=$matches[1]&tb=1\', \'top\' );
add_rewrite_rule( \'genres/[^/]+/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$\', \'index.php?movies=$matches[1]&feed=$matches[2]\', \'top\' );
add_rewrite_rule( \'genres/[^/]+/([^/]+)/(feed|rdf|rss|rss2|atom)/?$\', \'index.php?movies=$matches[1]&feed=$matches[2]\', \'top\' );
add_rewrite_rule( \'genres/[^/]+/([^/]+)/page/?([0-9]{1,})/?$\', \'index.php?&movies=$matches[1]&paged=$matches[2]\', \'top\' );
add_rewrite_rule( \'genres/[^/]+/([^/]+)(/[0-9]+)?/?$\', \'index.php?movies=$matches[1]&page=$matches[3]\', \'top\' );
add_rewrite_rule( \'genres/[^/]+/[^/]+/([^/]+)/?$\', \'index.php?attachment=$matches[1]\', \'top\' );
add_rewrite_rule( \'genres/[^/]+/[^/]+/([^/]+)/trackback/?$\', \'index.php?attachment=$matches[1]&tb=1\', \'top\' );
add_rewrite_rule( \'genres/[^/]+/[^/]+/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$\', \'index.php?attachment=$matches[1]&feed=$matches[2]\', \'top\' );
add_rewrite_rule( \'genres/[^/]+/[^/]+/([^/]+)/(feed|rdf|rss|rss2|atom)/?$\', \'index.php?attachment=$matches[1]&feed=$matches[2]\', \'top\' );
add_rewrite_rule( \'genres/[^/]+/[^/]+/([^/]+)/comment-page-([0-9]{1,})/?$\', \'index.php?attachment=$matches[1]&cpage=$matches[2]\', \'top\' );
add_rewrite_rule( \'genres/[^/]+/attachment/([^/]+)/?$\', \'index.php?attachment=$matches[1]\', \'top\' );
add_rewrite_rule( \'genres/[^/]+/attachment/([^/]+)/trackback/?$\', \'index.php?attachment=$matches[1]&tb=1\', \'top\' );
add_rewrite_rule( \'genres/[^/]+/attachment/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$\', \'index.php?attachment=$matches[1]&feed=$matches[2]\', \'top\' );
add_rewrite_rule( \'genres/[^/]+/attachment/([^/]+)/(feed|rdf|rss|rss2|atom)/?$\', \'index.php?attachment=$matches[1]&feed=$matches[2]\', \'top\' );
add_rewrite_rule( \'genres/[^/]+/attachment/([^/]+)/comment-page-([0-9]{1,})/?$\', \'index.php?attachment=$matches[1]&cpage=$matches[2]\', \'top\' );
add_rewrite_rule( \'genres/([^/]+)/trackback/?$\', \'index.php?genre=$matches[1]&tb=1\', \'top\' );
add_rewrite_rule( \'genres/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$\', \'index.php?genre=$matches[1]&feed=$matches[2]\', \'top\' );
add_rewrite_rule( \'genres/([^/]+)/(feed|rdf|rss|rss2|atom)/?$\', \'index.php?genre=$matches[1]&feed=$matches[2]\', \'top\' );
add_rewrite_rule( \'genres/([^/]+)/page/?([0-9]{1,})/?$\', \'index.php?genre=$matches[1]&paged=$matches[2]\', \'top\' );
add_rewrite_rule( \'genres/([^/]+)(/[0-9]+)?/?$\', \'index.php?genre=$matches[1]&page=$matches[2]\', \'top\' );
add_rewrite_rule( \'genres/[^/]+/([^/]+)/?$\', \'index.php?attachment=$matches[1]\', \'top\' );
add_rewrite_rule( \'genres/[^/]+/([^/]+)/trackback/?$\', \'index.php?attachment=$matches[1]&tb=1\', \'top\' );
add_rewrite_rule( \'genres/[^/]+/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$\', \'index.php?attachment=$matches[1]&feed=$matches[2]\', \'top\' );
add_rewrite_rule( \'genres/[^/]+/([^/]+)/(feed|rdf|rss|rss2|atom)/?$\', \'index.php?attachment=$matches[1]&feed=$matches[2]\', \'top\' );
add_rewrite_rule( \'genres/[^/]+/([^/]+)/comment-page-([0-9]{1,})/?$\', \'index.php?attachment=$matches[1]&cpage=$matches[2]\', \'top\' );
}