Skip to content

Instantly share code, notes, and snippets.

@aiiddqd
Created November 27, 2019 16:29
Show Gist options
  • Select an option

  • Save aiiddqd/49b7a053bfd3d04516e038be036f485a to your computer and use it in GitHub Desktop.

Select an option

Save aiiddqd/49b7a053bfd3d04516e038be036f485a to your computer and use it in GitHub Desktop.
wp-cli-example.php
<?php
namespace SB;
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
class AutoBotChangeSubjectsNames {
public static function init() {
if ( defined( 'WP_CLI' ) && WP_CLI ) {
\WP_CLI::add_command( 'sb_change_subjects_names', [ __CLASS__, 'sb_change_subjects_names' ] );
}
}
/**
* Основная функция
*
* @param $args
* @param $assoc_args
*/
public static function sb_change_subjects_names( $args, $assoc_args ) {
if ( ! isset( $assoc_args['total'] ) ) {
$assoc_args['total'] = 100;
}
$posts = new \WP_Query(
array(
'post_type' => 'team',
'posts_per_page' => intval( $assoc_args['total'] ),
//'order' => 'DESC',
)
);
// Добовляем прогресс бар
$progress = \WP_CLI\Utils\make_progress_bar( 'Фильтруем ' . $assoc_args['total'], intval( $assoc_args['total'] ) );
$numberPosts = 0;
while ( $posts->have_posts() ) {
$posts->the_post();
$numberPosts ++;
\SB\SubjectsTaxonomy::update_term_name(get_the_ID());
//\WP_CLI::line( get_the_title() );
$progress->tick();
}
$progress->finish();
}
}
AutoBotChangeSubjectsNames::init();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment