【问题标题】:WordPress custom post type pagination returns 404 page errorWordPress 自定义帖子类型分页返回 404 页面错误
【发布时间】:2020-03-22 05:26:16
【问题描述】:

我创建了一个与我的页面同名的自定义帖子类型。我用自定义代码修复了这个问题,现在可以工作了:

'has_archive' => false,
'rewrite' => array(
'slug' =>'case-studies',
'with_front' => false 

但是现在,当我点击自定义帖子类型“案例研究”帖子列表中的分页链接时(或输入像 www.beezer.com/case-studies/page/2 这样的 URL),我得到了 404 页面。

我尝试了很多自定义代码,包括使用 Monkeyman Rewrite Analyzer,但它不起作用。

function my_pagination_rewrite() {
    add_rewrite_rule('case-studies/([^/]+)?(:/([0-9]+))?/?$', 'index.php?category_name=case-studies&paged=$matches[1]', 'top'); 
} 

add_action('init', 'my_pagination_rewrite');

谁能帮忙?

【问题讨论】:

    标签: php wordpress pagination http-status-code-404 custom-post-type


    【解决方案1】:

    首先 - 请将“has_archive”改为“true”

    'has_archive' => true
    

    你能分享更多详细的代码吗?我的意思是创建 CPT 和存档页面的代码。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-06-07
      • 1970-01-01
      • 1970-01-01
      • 2014-09-29
      • 2014-05-20
      • 2017-09-22
      • 2014-07-12
      • 1970-01-01
      相关资源
      最近更新 更多