Hello world!
Welcome to WordPress. This is your first post. Edit or delete it, then start writing!
// Add to functions.php (optional advanced feature) if (defined('WP_CLI') && WP_CLI) { WP_CLI::add_command('job-categories', function($args, $assoc_args) { $action = $args[0] ?? 'list'; if ($action === 'list') { $cats = get_terms(array('taxonomy' => 'job_listing_category', 'hide_empty' => false)); foreach($cats as $cat) { WP_CLI::line(sprintf("%-30s %d jobs", $cat->name, $cat->count)); } } if ($action === 'delete-empty' && !empty($assoc_args['confirm'])) { $cats = get_terms(array('taxonomy' => 'job_listing_category', 'hide_empty' => false)); $deleted = 0; foreach($cats as $cat) { if ($cat->count == 0) { wp_delete_term($cat->term_id, 'job_listing_category'); $deleted++; } } WP_CLI::success("Deleted {$deleted} empty categories"); } }); } // Usage: wp job-categories list // Usage: wp job-categories delete-empty --confirm
Welcome to WordPress. This is your first post. Edit or delete it, then start writing!