Skip to content

Instantly share code, notes, and snippets.

@kbcarte
Last active August 23, 2022 14:05
Show Gist options
  • Save kbcarte/b2c3770c0967a657b7679a15ebda054d to your computer and use it in GitHub Desktop.
Save kbcarte/b2c3770c0967a657b7679a15ebda054d to your computer and use it in GitHub Desktop.
Update all pages/posts Yoast SEO Advanced settings to be index by google

Update all pages/posts to be index by google. This is a global update and will set all posts/pages to be indexed.

UI found in post/page in the Yoast SEO setction, under Advanced

Run this query in phpmyadmin, adminer, or what ever db client you are using.

UPDATE `wp_postmeta` SET `meta_value`='2' WHERE `meta_key`='_yoast_wpseo_meta-robots-noindex'

Update all pages/posts to allow link follow from google.

DELETE FROM `wp_postmeta` WHERE `meta_key`='_yoast_wpseo_meta-robots-nofollow'

Update the posts and pages

We also need to trigger an update through WordPress so the new DB values take effect. Place this in your footer.php (or anywhere it can be ran from) and refresh the page so it executes.

$args_post = array(
  'post_type' => 'post',
  'post_status' => 'publish',
  'posts_per_page' => -1
);
$myposts = get_posts($args_post);
foreach($myposts as $p) {
  wp_update_post($p);
}

$args_page = array(
  'post_type' => 'page',
  'post_status' => 'publish',
  'posts_per_page' => -1
);
$mypages = get_posts($args_page);
foreach($mypages as $p) {
  wp_update_post($p);
}

Should be all set from here! Don't forget to remove the update posts code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment