Skip to main content
GEO AI provides WP-CLI commands for bulk auditing, automation, and server-side SEO analysis.
Prerequisites: WP-CLI must be installed on your server. Learn more
File: includes/class-geoai-cli.php

Installation Check

Verify GEO AI’s CLI commands are registered:
wp geoai
Expected output:
usage: wp geoai audit <post|all> [--min-score=<score>]

See 'wp help geoai audit' for more information.

Commands

wp geoai audit

Run SEO audits on posts via command line.
Audit a specific post by ID:
wp geoai audit 123
Output:
Success: Post #123 audited. Score: 85/100
Issues:
  - [warning] Focus keyword not found in meta description.
  - [good] Focus keyword found in title.
  - [good] Readability is good (Flesch score: 68.5).
Parameters:
  • <post_id> - WordPress post ID (required)
What it does:
  1. Retrieves post content
  2. Runs GeoAI_Analyzer::analyze_post()
  3. Displays total score and all issues
  4. Exits with code 0 on success, 1 on error

Implementation Details

Source Code

namespace GeoAI\CLI;

class GeoAI_CLI {
    /**
     * Audit a post or all posts.
     *
     * ## OPTIONS
     *
     * <post|all>
     * : Post ID or 'all' to audit all posts.
     *
     * [--min-score=<score>]
     * : Minimum score threshold for 'all' mode.
     *
     * ## EXAMPLES
     *
     *     wp geoai audit 123
     *     wp geoai audit all --min-score=80
     */
    public function audit( $args, $assoc_args ) {
        $target    = $args[0] ?? 'all';
        $min_score = $assoc_args['min-score'] ?? 0;

        if ( 'all' === $target ) {
            $this->audit_all( $min_score );
        } else {
            $this->audit_post( absint( $target ) );
        }
    }
}

// Register command
\WP_CLI::add_command( 'geoai', __NAMESPACE__ . '\\GeoAI_CLI' );

Error Handling

private function audit_post( $post_id ) {
    $analyzer = \GeoAI\Core\GeoAI_Analyzer::get_instance();
    $result   = $analyzer->analyze_post( $post_id );

    if ( is_wp_error( $result ) ) {
        \WP_CLI::error( $result->get_error_message() );
        // Exits with code 1
    }

    \WP_CLI::success(
        sprintf(
            'Post #%d audited. Score: %d/100',
            $post_id,
            $result['scores']['total']
        )
    );
}

Usage Examples

Bulk Audit for Reporting

Audit all posts and save output to CSV:
wp geoai audit all --format=csv > seo-scores.csv
Current version doesn’t support --format flag. Planned for v1.1.
Workaround with current version:
wp geoai audit all 2>&1 | tee seo-audit-$(date +%Y%m%d).log

Scheduled Audits

Add to crontab for weekly SEO health checks:
# Every Monday at 2 AM
0 2 * * 1 cd /var/www/html && wp geoai audit all --min-score=60 | mail -s "Low SEO Scores" [email protected]

CI/CD Integration

Run audits in deployment pipeline:
# .github/workflows/content-quality.yml
name: Content Quality Check
on:
  push:
    paths:
      - 'content/**'

jobs:
  audit:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Install WordPress & GEO AI
        run: |
          # Setup WordPress environment
          wp core install --url=example.com
          wp plugin activate geo-ai
      - name: Run SEO Audit
        run: |
          SCORE=$(wp geoai audit all --min-score=70)
          if [ $? -ne 0 ]; then
            echo "SEO audit failed minimum score"
            exit 1
          fi

Quality Gates

Reject posts below quality threshold:
#!/bin/bash
POST_ID=$1
MIN_SCORE=75

RESULT=$(wp geoai audit $POST_ID 2>&1)
SCORE=$(echo $RESULT | grep -oP 'Score: \K[0-9]+')

if [ $SCORE -lt $MIN_SCORE ]; then
    echo "❌ Post score ($SCORE) below minimum ($MIN_SCORE)"
    exit 1
else
    echo "✅ Post meets quality standards ($SCORE/$MIN_SCORE)"
    exit 0
fi

Performance Considerations

API Rate Limits

Each audit calls Google Gemini API. Free tier limits:
  • 60 requests/minute
  • 1,500 requests/day
For bulk audits, add delays:
for id in $(wp post list --post_type=post --field=ID); do
  wp geoai audit $id
  sleep 2  # 2 second delay
done

Memory Usage

Bulk audits load all posts into memory. For 1000+ posts:
# Increase PHP memory limit
wp geoai audit all --allow-root \
  --extra-php="-d memory_limit=512M"

Progress Tracking

WP-CLI shows progress bars automatically:
$progress = \WP_CLI\Utils
    \make_progress_bar( 'Auditing posts', count( $posts ) );

foreach ( $posts as $post ) {
    // ... audit logic ...
    $progress->tick();
}

$progress->finish();

Batch Processing

For very large sites (5000+ posts):
# Process in batches of 100
for i in {0..50}; do
  OFFSET=$((i * 100))
  wp post list --post_type=post \
    --posts_per_page=100 \
    --offset=$OFFSET \
    --field=ID | xargs -I {} wp geoai audit {}
done

Output Formats

Success Message

Success: Post #123 audited. Score: 85/100
Issues:
  - [error] Keyword density is too low (0.21%). Aim for 0.5-2.5%.
  - [warning] 32% of sentences are too long (>20 words).
  - [good] Focus keyword found in title.
  - [good] Readability is good (Flesch score: 68.5).

Error Messages

Error: Post not found.
Error: Failed to analyze post: API request failed.

Issue Severity Levels

PrefixSeverityColor (in terminal)
[error]High priority fixRed
[warning]Should fixYellow
[ok]AcceptableBlue
[good]Performing wellGreen

Extending WP-CLI

Add custom subcommands to GEO AI:
// In your theme/plugin
add_action( 'cli_init', function() {
    if ( ! class_exists( 'WP_CLI' ) ) {
        return;
    }
    
    WP_CLI::add_command( 'geoai export', function( $args, $assoc_args ) {
        $posts = get_posts( array(
            'post_type'      => 'post',
            'posts_per_page' => -1,
            'meta_key'       => '_geoai_keyword_score',
        ));
        
        foreach ( $posts as $post ) {
            $score = get_post_meta( $post->ID, '_geoai_keyword_score', true );
            WP_CLI::line( sprintf( '%d,%s,%d', 
                $post->ID, 
                $post->post_title, 
                $score 
            ));
        }
        
        WP_CLI::success( 'Export complete.' );
    });
});
Usage:
wp geoai export > scores.csv

Planned Commands (v1.1+)

The following commands are planned but not yet implemented:

wp geoai fix

Apply automated quick fixes:
# Apply all auto-fixes to a post
wp geoai fix 123 --all

# Apply specific fixes
wp geoai fix 123 --add-meta-description --fix-title-length

# Dry run (show what would be fixed)
wp geoai fix 123 --dry-run

wp geoai report

Generate SEO health reports:
# HTML report
wp geoai report --format=html > seo-report.html

# JSON for API consumption
wp geoai report --format=json

# Email report
wp geoai report [email protected]

wp geoai clear-cache

Clear analyzer caches:
# Clear all GEO AI caches
wp geoai clear-cache

# Clear specific post cache
wp geoai clear-cache --post=123

wp geoai settings

Manage settings via CLI:
# Get setting
wp geoai settings get geoai_compat_mode

# Set setting
wp geoai settings set geoai_compat_mode coexist

# Export settings
wp geoai settings export > settings.json

# Import settings
wp geoai settings import settings.json

Troubleshooting

Error: Error: 'geoai' is not a registered wp command.Solutions:
  1. Verify GEO AI is active: wp plugin list
  2. Check if WP-CLI constant is defined in CLI context
  3. Ensure class-geoai-cli.php is loaded
  4. Try: wp cli cache clear
Error: Error: Failed to analyze post: API request timed out.Solutions:
  1. Add delays between requests (see Performance section)
  2. Increase PHP timeout: --extra-php="-d max_execution_time=300"
  3. Use smaller batches instead of audit all
  4. Check Gemini API quota in Google Cloud Console
Error: Fatal error: Allowed memory size exhaustedSolutions:
  1. Increase memory: --extra-php="-d memory_limit=512M"
  2. Process in smaller batches
  3. Use wp post list with --posts_per_page to paginate
Error: Error: You do not have permission to run this command.Solutions:
  1. Run as correct user: sudo -u www-data wp geoai audit all
  2. Or use: wp geoai audit all --allow-root (not recommended for production)

Analyzers

Learn what each analyzer checks

REST API

HTTP alternative to WP-CLI

Automation

Automate SEO audits with cron

WP-CLI Docs

Official WP-CLI documentation

Build docs developers (and LLMs) love