Created
May 18, 2023 17:43
-
-
Save mgratch/1971033a442302ce465ca8ca2d8d87c3 to your computer and use it in GitHub Desktop.
Use WP-CLI to enter `wp shell`, enter the following class, and then run `(new SEO_Update_Command())->__invoke()` to start the process.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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');} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Running
update_post_metaalone does not triggerwp_update_postwhich may be necessary to rebuild Yoast indexables. This can be run after the initial run ofSEO_Update_Command()(if it does not includewp_udpate_postalready.if (class_exists('WP_CLI')) { class SEO_Reindex_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"); $repository = YoastSEO()->classes->get (\Yoast\WP\SEO\Repositories\Indexable_Repository::class); $builder = YoastSEO()->classes->get(\Yoast\WP\SEO\Builders\Indexable_Builder::class); $progress = \WP_CLI\Utils\make_progress_bar('Reindexing...', count($post_ids)); foreach($post_ids as $post_id) { $indexable = $repository->find_by_id_and_type($post_id, 'post', false); $builder->build_for_id_and_type($post_id, 'post', $indexable); $progress->tick(); } $progress->finish(); WP_CLI::success('Indexables rebuilt.'); }} WP_CLI::add_command('seo_reindex', 'SEO_Reindex_Command'); }(new SEO_Reindex_Command())->__invoke()