-
-
Save mgratch/1971033a442302ce465ca8ca2d8d87c3 to your computer and use it in GitHub Desktop.
if (class_exists('WP_CLI')) { class SEO_Update_Command { public function __invoke() { global $wpdb; $post_ids = $wpdb->get_col("SELECT ID FROM $wpdb->posts WHERE post_type = 'salary_market_data' AND post_parent != 0"); $progress = \WP_CLI\Utils\make_progress_bar( 'Updating...', count($post_ids)); foreach($post_ids as $post_id) { update_post_meta($post_id, "_yoast_wpseo_meta-robots-noindex", 1); $progress->tick(); } $progress->finish(); WP_CLI::success('Meta values updated successfully.'); }} WP_CLI::add_command('seo_update', 'SEO_Update_Command');} |
The following updates the publish dates associated with a salary_market_data
post and sets both nofollow
and noindex
to 2
Note this only targets salary_market_data
posts starting with the letter A
. Revise script on subsequent runs to target different letters.
if (class_exists('WP_CLI')) { class SEO_Update_Command { public function __invoke() { global $wpdb; $post_ids = $wpdb->get_col("SELECT ID FROM $wpdb->posts WHERE post_type = 'salary_market_data' AND post_title LIKE 'A%'"); $progress = \WP_CLI\Utils\make_progress_bar('Updating...', count($post_ids)); foreach ($post_ids as $post_id) { update_post_meta($post_id, "_yoast_wpseo_meta-robots-nofollow", 2); update_post_meta($post_id, '_yoast_wpseo_meta-robots-noindex', 2); $local_time = current_time('mysql'); $gmt_time = current_time('mysql', 1); wp_update_post([ 'ID' => $post_id, 'post_date' => $local_time, 'post_date_gmt' => $gmt_time, 'post_modified' => $local_time, 'post_modified_gmt' => $gmt_time ]); $progress->tick(); } $progress->finish(); WP_CLI::success('Meta values and post dates updated successfully.'); } } WP_CLI::add_command('seo_update', 'SEO_Update_Command'); }
For easy future reference, here's the updated SQL to set all
jobs
CPT to bothnoindex
andnofollow
:if (class_exists('WP_CLI')) { class SEO_Update_Command { public function __invoke() { global $wpdb; $post_ids = $wpdb->get_col("SELECT ID FROM $wpdb->posts WHERE post_type = 'jobs'"); $progress = \WP_CLI\Utils\make_progress_bar( 'Updating...', count($post_ids)); foreach($post_ids as $post_id) { update_post_meta($post_id, "_yoast_wpseo_meta-robots-nofollow", 1); update_post_meta($post_id, "_yoast_wpseo_meta-robots-noindex", 1); $progress->tick(); } $progress->finish(); WP_CLI::success('Meta values updated successfully.'); }} WP_CLI::add_command('seo_update', 'SEO_Update_Command');}