GoogleSearrchConsoleでサイトマップが読み込めませんでしたと出る場合の対処方法を紹介します。
対象となるのはCSVで流し込んだりAPIで流し込んだりで大量の記事を公開している人です。
また、プラグインにGoogle XML Sitemapsを使用している場合です。
大量の記事を流し込むと当然その月のsitemapに乗る件数も多くなります。
この件数が50000件を超えるとどうやら認識されなくなるみたいです。
重いファイルは自動的にスキップされるためです。なのでこの50000件が正確かどうかは不明ですが、目安にはなると思います。
以下の方法で1か月分の特定のpost_typeのサイトマップを3つに分けて対応します。
(一日に膨大な量を流し込んでいる場合は改良が必要です。)
Google XML Sitemapsプラグインの「sitemap-builder.php」を編集していきます。
まず、「Index」関数の変更です。
if($posts) {
if($postType=="post") $hasPosts = true;
$hasEnabledPostTypesPosts = true;
foreach($posts as $post) {
$gsg->AddSitemap("pt", $postType . "-" . sprintf("%04d-%02d", $post->year, $post->month), $gsg->GetTimestampFromMySql($post->last_mod));
}
}
この部分を以下のようにし、出力ファイルを3つにします。
if($posts) {
if($postType=="post") $hasPosts = true;
$hasEnabledPostTypesPosts = true;
foreach($posts as $post) {
if($postType=="movie") {
$gsg->AddSitemap("pt", $postType . "-" . sprintf("%04d-%02d", $post->year, $post->month+20), $gsg->GetTimestampFromMySql($post->last_mod));
$gsg->AddSitemap("pt", $postType . "-" . sprintf("%04d-%02d", $post->year, $post->month+40), $gsg->GetTimestampFromMySql($post->last_mod));
}
$gsg->AddSitemap("pt", $postType . "-" . sprintf("%04d-%02d", $post->year, $post->month), $gsg->GetTimestampFromMySql($post->last_mod));
}
}
if文内のpost_typeをカスタム投稿などの任意の名前に変更してください。
月に+20された名前のファイルが生成されるようになります。
次に「BuildPosts」関数を変更していきます。
if(preg_match('/^([0-9]{4})\-([0-9]{2})$/', $params, $matches)) {
$year = $matches[1];
$month = $matches[2];
この部分を以下のように変更します。
if(preg_match('/^([0-9]{4})\-([0-9]{2})$/', $params, $matches)) {
$year = $matches[1];
$month = $matches[2];
if($postType == "movie") {
if($month >= 21 && $month <= 32) {
$month -= 20;
$dayFirst = 11;
$dayLast = 20;
} elseif ($month >= 41 && $month <= 52) {
$month -= 40;
$dayFirst = 21;
$dayLast = 31;
} else {
$dayFirst = 1;
$dayLast = 10;
}
}
3等分するそれぞれに対応する日付を設定しています。
続いて上の設定をSQLに反映させます。
$qs = "
SELECT
p.ID,
p.post_author,
p.post_status,
p.post_name,
p.post_parent,
p.post_type,
p.post_date,
p.post_date_gmt,
p.post_modified,
p.post_modified_gmt,
p.comment_count
FROM
{$wpdb->posts} p
WHERE
p.post_password = ''
AND p.post_type = '%s'
AND p.post_status = 'publish'
AND YEAR(p.post_date_gmt) = %d
AND MONTH(p.post_date_gmt) = %d
AND DAY(p.post_date_gmt) >= {$dayFirst} //日付下限
AND DAY(p.post_date_gmt) <= {$dayLast} //日付上限
{$exPostSQL}
{$exCatSQL}
ORDER BY
p.post_date_gmt DESC
";
以上の作業を行うことでサイトマップを複数に分けることができ、コンソールにも読みこんでもらうことができると思います。