将分数添加到wordpress自定义帖子类型

时间:2019-04-23 10:04:19

标签: wordpress permalinks slug

我的自定义帖子类型“作品”具有以下代码,但是当前代码在链接上不允许得分“-”吗?我该怎么解决?

function works_rewrites_init($post_link, $post = 0){

  add_rewrite_rule('works\/([A-Za-z0-9]+)?\/([0-9]+)?(page\/)?([0-9]+)?\/?$', 'index.php?paged=$matches[4]&post_type=works&workscat=$matches[1]&p=$matches[2]', 'top');
}

1 个答案:

答案 0 :(得分:0)

function works_rewrites_init($post_link, $post = 0){
    $rule = 'works\/([A-Za-z0-9\-]+)?\/([0-9]+)?(page\/)?([0-9]+)?\/?$';
  $pageID = $post->ID;
  add_rewrite_rule($rule, 'index.php?paged=$matches[4]&post_type=works&workscat=$matches[1]&p=$matches[2]', 'top');
}
add_action('init', 'works_rewrites_init');