0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

WordPressのPermalink structureが "/%category%/%post_id%/" かつCategory baseが "." の時2ページ目以降が404になる問題の解決案

Last updated at Posted at 2023-10-11

Permalink structureが "/%category%/%post_id%/" かつCategory baseが "." の時のWordPressの振る舞い(憶測)

おそらく、

  • /[カテゴリ名]/ → カテゴリ記事一覧
  • /[カテゴリ名]/[ID]/ → IDが[ID]の記事
  • /[カテゴリ名]/page/2/ → IDがpage/2って記事? → 404

となる。

解決案

十分に検証していません。

  • 全てのカテゴリのリライトルールを先頭に追加する。

    add_action('init', function () {
        foreach (get_categories(['hide_empty' => false]) as $i) {
            add_rewrite_rule(
                "({$i->slug})/page/?([0-9]{1,})/?$",
                'index.php?category_name=$matches[1]&paged=$matches[2]',
                'top'
            );
        }
    });
    
  • Settings > Permalink SettingsでSave Changesを押す

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?