TechEarl

Build a Custom Product URL Structure in WordPress (Remove /product/ and /shop/)

How to build a custom product URL structure in WooCommerce: change or remove the /product/ and /shop/ bases from Settings > Permalinks, do it in code with a permalink filter plus add_rewrite_rule, serve any custom post type from the root without its parent slug, build /make/model/year/ catalog URLs, and avoid the 404 collisions that come from a base-less slug.

Ishan KarunaratnePublished ⏱️ 18 min readUpdated
Share thisCopied
How to build a custom WooCommerce product URL structure: change the /product/ and /shop/ base in Settings > Permalinks or filter the product permalink and add a rewrite rule, while avoiding the slug-collision 404s a base-less product URL causes.

To change the WooCommerce product URL structure, you have two levers. The quick one is Settings > Permalinks, where WooCommerce lets you swap the /product/ base for the shop page name or a custom prefix. The thorough one is code: filter the product permalink to emit the clean URL, then add a rewrite rule so WordPress can resolve it back. The same mechanics remove the parent slug from any custom post type URL (serving /docs/my-doc/ at /my-doc/) and build three-level /make/model/year/ catalog URLs, both covered further down.

Products are a custom post type (product) with a fixed /product/ URL base, and the only thing standing between you and clean example.com/blue-widget URLs is that base plus a slug-collision problem nobody warns you about. The settings page alone cannot fully blank the base without breaking routing, which is why the code route exists.

The honest version up front: a completely base-less product URL (/blue-widget, no prefix at all) is achievable but fragile, because WordPress then cannot tell a product apart from a page, post, or category that happens to share the slug. I will show the code, then show exactly where it bites and how to guard it.

The structure options, ranked

There are realistically four shapes you can give a WooCommerce product URL:

StructureExampleBase collision riskMy take
Default base/product/blue-widgetNoneSafe, ugly, what you are escaping
Custom single base/store/blue-widgetNoneCleanest safe option
Category in path/widgets/blue-widgetLowGood for browse-heavy catalogs
No base at all/blue-widgetHighLooks best, breaks easiest

The jump in risk happens at the last row. Everything with a base (/product/, /store/, a category segment) gives WordPress a stable token to route on. Strip the base entirely and you are asking the rewrite system to treat a bare slug as a product first, which collides with every page and post on the site.

WooCommerce adds a Product permalinks block to the standard WordPress permalinks screen (Settings > Permalinks). On any non-plain permalink structure, it offers four product-base choices:

  • Default maps to example.com/product/blue-widget.
  • Shop base uses your shop page slug: example.com/shop/blue-widget.
  • Shop base with category nests the category: example.com/shop/widgets/blue-widget.
  • Custom base lets you type any prefix, e.g. example.com/store/blue-widget.

Below that, the Product category base field controls the taxonomy URL, which defaults to /product-category/ (so categories live at example.com/product-category/widgets).

For most stores this UI is all you need. Pick Custom base, type store (or your brand word), save, and you have clean-enough URLs with zero code. Two things WooCommerce's own docs are firm about:

  1. Do not blank the Custom base field hoping for /blue-widget. WooCommerce treats an empty custom base as "use the default," not "remove the base." There is no supported UI path to a truly base-less product URL, and trying to fake it by setting the base to / produces the collision problem in the next section.
  2. Keep the product base and the category base distinct. WordPress requires these values to be unique so it can tell a product URL from a category URL. Set the product base to shop and the category base to shop and routing breaks; pages start resolving to the wrong content or 404.

If you only ever read this far and pick a short custom base, you have done the right thing for 90% of stores.

When you want a base-less or otherwise non-standard structure the settings page will not give you, it takes two coordinated pieces, because a WordPress URL has two directions:

  • Emit: when WooCommerce prints a link to a product, it should print your clean URL. That is the post_type_link filter.
  • Resolve: when a browser requests that clean URL, WordPress has to recognize it as a product. That is add_rewrite_rule().

Get one without the other and you get either pretty links that 404, or working links that still render the old /product/ form everywhere. Here is the pair, in a must-use plugin:

php
<?php
/**
 * Plugin Name: TE Product URLs
 * Plugin URI:  https://techearl.com/wordpress-custom-product-url-structure
 * Description: Builds a custom WooCommerce product URL structure by filtering the
 *              product permalink and adding a matching rewrite rule.
 * Version:     1.0.0
 * Author:      Ishan Karunaratne
 * Author URI:  https://techearl.com
 * License:     GPL-2.0-or-later
 * Text Domain: te-product-urls
 */

if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

const TE_PRODUCT_URL_BASE = 'store';

// EMIT: rewrite the product permalink to /<base>/<slug>.
function te_product_permalink( $permalink, $post ) {
    if ( 'product' !== $post->post_type ) {
        return $permalink;
    }
    return home_url( '/' . TE_PRODUCT_URL_BASE . '/' . $post->post_name . '/' );
}
add_filter( 'post_type_link', 'te_product_permalink', 10, 2 );

// RESOLVE: teach WordPress to route /<base>/<slug> back to the product.
function te_product_rewrite_rule() {
    add_rewrite_rule(
        '^' . TE_PRODUCT_URL_BASE . '/([^/]+)/?$',
        'index.php?post_type=product&name=$matches[1]',
        'top'
    );
}
add_action( 'init', 'te_product_rewrite_rule' );

The post_type_link filter only touches the product post type and leaves every other link untouched. The rewrite rule's regex captures the slug after your base and hands it to the standard post_type=product&name= query that WooCommerce already understands. I register the rule with 'top' so it is evaluated ahead of WordPress's looser default rules; more on why that matters below.

To remove the base entirely, set TE_PRODUCT_URL_BASE to '' and change the regex to ^([^/]+)/?$. That is the line you should hesitate at. Read the next section before you ship it.

The caveat that costs people a weekend: slug collisions and 404s

Here is the failure mode that is missing from most "remove /product/ from WooCommerce" tutorials.

A rewrite rule like ^([^/]+)/?$ -> post_type=product&name=$1 says "any single path segment is a product slug." But /about, /contact, /blog, and every product category slug are also single path segments. With the base-less rule registered at 'top', WordPress tests the product rule first, so a request for /about gets handed to the product query as name=about. If no product named about exists, you get a 404 on your About page. If a product does happen to share that slug, you get the wrong content entirely.

It is worse than a static list of pages, because slugs are created at runtime. The day a client publishes a product named "Contact Kit" with slug contact-kit, nothing breaks. The day they publish a product whose slug collides with an existing page, the page disappears behind the product (or vice versa, depending on rule order). You cannot enumerate the collisions up front.

There are three honest ways to live with this, in order of how much I trust them:

  1. Keep a base (the real fix). A one-word base like /store/ removes the collision class completely, because /store/blue-widget can only ever be a product. You still get a short, clean URL and you keep your sanity. This is what I ship on client sites.
  2. Resolve, do not pre-empt. Register the base-less rule at 'bottom' instead of 'top', so WordPress matches real pages, posts, and category archives first and only falls through to the product query when nothing else claims the slug. This protects existing content, but it is fragile in the other direction: a future page created with a slug that an existing product already uses will now shadow the product. Rule order decides who wins; there is no order that is safe in both directions.
  3. Enforce slug uniqueness across products and pages. Hook wp_unique_post_slug (or validate on save) so a product can never take a slug already used by a page/post, and vice versa. This is the only approach that makes a truly base-less structure correct rather than merely usually-fine, and it is real work: you are reimplementing part of WordPress's namespacing, you have to handle existing collisions at rollout, and you own that code forever.

If after all that you still want no base, do option 3 and accept the maintenance. For everyone else, a short custom base is not a compromise, it is the right answer.

Two structures give you clean URLs without inviting the collision problem:

  • Single custom base: /store/blue-widget. One short segment, no ambiguity, set it in Settings > Permalinks (Custom base) with zero code. This is my default recommendation.
  • Category in the path: /widgets/blue-widget. WooCommerce's "Shop base with category" plus a code tweak to drop the shop word gets you here. It reads well for catalogs people browse by category, and the category segment doubles as the disambiguating token, so it carries far less collision risk than a bare slug. The tradeoff is that moving a product between categories changes its URL, so set up redirects if you reorganize.

Both keep a routing anchor in the path, which is the entire point. The base-less /blue-widget looks marginally cleaner and costs you disproportionately more to keep correct.

Remove the parent slug from a WordPress URL

The same emit-and-resolve pair works for any custom post type, not just products. A common request is serving a doc post type from the site root, so a page that normally lives at /docs/my-doc/ answers at /my-doc/. As a must-use plugin:

php
<?php
/**
 * Plugin Name: TE Root Slugs
 * Plugin URI:  https://techearl.com/wordpress-custom-product-url-structure
 * Description: Serves the "doc" custom post type from the site root, dropping the /docs/ prefix, with a 301 from old URLs.
 * Version:     1.0.0
 * Author:      Ishan Karunaratne
 * Author URI:  https://techearl.com
 * License:     GPL-2.0-or-later
 * Text Domain: te-root-slugs
 */

// 1. Render permalinks WITHOUT the /docs/ prefix.
function te_root_permalink( $post_link, $post ) {
    if ( 'doc' === $post->post_type && 'publish' === $post->post_status ) {
        $post_link = home_url( '/' . $post->post_name . '/' );
    }
    return $post_link;
}
add_filter( 'post_type_link', 'te_root_permalink', 10, 2 );

// 2. Resolve a root-level slug back to the right doc.
function te_root_rewrite() {
    add_rewrite_rule(
        '^([^/]+)/?$',
        'index.php?post_type=doc&name=$matches[1]',
        'top'
    );
}
add_action( 'init', 'te_root_rewrite' );

Skip either half and it breaks in a specific way. Filter without rule: every link renders as /my-doc/ and every click 404s. Rule without filter: /my-doc/ resolves, but get_permalink(), the canonical tag, the sitemap and menus still emit /docs/my-doc/, because generated permalinks come from the post type's registered rewrite slug, not from your rule. That leaves two live URLs and a canonical pointing at the one you are retiring. Leave the registered 'rewrite' => array( 'slug' => 'docs' ) as it is; there is no rewrite value that safely means "sit at the root", and the old structure is a useful fallback while you migrate.

301 the old /docs/ URLs

If /docs/my-doc/ was ever indexed, redirect it once WordPress has resolved the doc:

php
function te_root_redirect_old() {
    if ( is_singular( 'doc' ) ) {
        $current = home_url( add_query_arg( array(), $GLOBALS['wp']->request ) );
        $clean   = home_url( '/' . get_post_field( 'post_name', get_queried_object_id() ) . '/' );

        if ( untrailingslashit( $current ) !== untrailingslashit( $clean ) ) {
            wp_safe_redirect( $clean, 301 );
            exit;
        }
    }
}
add_action( 'template_redirect', 'te_root_redirect_old' );

A genuine request to /my-doc/ already matches the clean form, so the condition is false and there is no redirect loop. wp_safe_redirect() validates the target against your allowed hosts; always exit straight after.

Guard the root namespace

A root rule has exactly the collision problem described above for products: /pricing/ the doc and /pricing/ the Page cannot both win, and a Page added months later can collide with an existing doc. You need an explicit collision policy, and two guards to enforce it. Mine is: a published doc owns its slug; anything else falls through to a Page, then a post, then a normal 404.

The first guard has to run on the request filter, not pre_get_posts. By the time pre_get_posts fires, the root rule has already matched and set post_type=doc&name=about; widening the post types there does not send the request back to the Page rule, so a missing doc still 404s the About page. The request filter sees the parsed query vars before the query is built, so it can replace them:

php
function te_root_resolve( $query_vars ) {
    if ( empty( $query_vars['post_type'] ) || 'doc' !== $query_vars['post_type'] || empty( $query_vars['name'] ) ) {
        return $query_vars;
    }
    $slug = $query_vars['name'];

    // A published doc owns this slug.
    if ( te_root_doc_exists( $slug ) ) {
        return $query_vars;
    }
    // No doc: hand the request back to core as a Page, then as a post.
    if ( get_page_by_path( $slug ) ) {
        return array( 'pagename' => $slug );
    }
    return array( 'name' => $slug );
}
add_filter( 'request', 'te_root_resolve' );

function te_root_doc_exists( $slug ) {
    $found = get_posts( array(
        'post_type'   => 'doc',
        'name'        => $slug,
        'post_status' => 'publish',
        'numberposts' => 1,
        'fields'      => 'ids',
    ) );
    return ! empty( $found );
}

Second, stop the collision at save time by suffixing a doc slug that already belongs to a Page or post:

php
function te_root_unique_slug( $data, $postarr ) {
    if ( 'doc' !== $data['post_type'] || empty( $data['post_name'] ) ) {
        return $data;
    }
    $clash = get_page_by_path(
        $data['post_name'],
        OBJECT,
        array( 'page', 'post' )
    );
    if ( $clash ) {
        $data['post_name'] = wp_unique_post_slug(
            $data['post_name'] . '-doc',
            $postarr['ID'] ?? 0,
            $data['post_status'],
            'doc',
            0
        );
    }
    return $data;
}
add_filter( 'wp_insert_post_data', 'te_root_unique_slug', 10, 2 );

The filter only runs when a doc is saved, so it does not stop the reverse case: a Page published later with a slug a doc already owns is shadowed by the doc under this policy. Check the slug before publishing such a Page, or extend the filter to the page post type. Also keep a small denylist of slugs the root pattern must never claim (wp-admin, feed, wp-json, your structural page slugs) and bail out of doc resolution for them. Flush the rules (below), then confirm both ends:

bash
# old prefixed URL should permanently redirect to the root
curl -sI https://example.com/docs/my-doc/ | grep -i -E '^(HTTP|location)'
# HTTP/2 301
# location: https://example.com/my-doc/

# the new root URL should serve the doc directly
curl -sI https://example.com/my-doc/ | grep -i '^HTTP'
# HTTP/2 200

curl -sI https://example.com/about/ should still return the Page, not the doc template. If it does not, the rule is shadowing pages and the request guard is missing. On Windows, curl in PowerShell is an alias for Invoke-WebRequest; call curl.exe to get this behavior.

Make, model and year URLs

Directory and catalog sites often key listings on a three-level hierarchy instead of a single slug: /vehicles/toyota/camry/2024/. Capture the three segments into custom query vars, register them, then read them in pre_get_posts. Register the most specific rule first, all at 'top', so the partial paths /vehicles/toyota/camry/ (every year of one model) and /vehicles/toyota/ (every model of one make) work as archives too:

php
function te_register_vehicle_routes() {
    // /vehicles/toyota/camry/2024/  - a single make+model+year listing
    add_rewrite_rule(
        '^vehicles/([^/]+)/([^/]+)/([^/]+)/?$',
        'index.php?te_make=$matches[1]&te_model=$matches[2]&te_year=$matches[3]',
        'top'
    );
    // /vehicles/toyota/camry/  - every year of one model
    add_rewrite_rule(
        '^vehicles/([^/]+)/([^/]+)/?$',
        'index.php?te_make=$matches[1]&te_model=$matches[2]',
        'top'
    );
    // /vehicles/toyota/  - every model of one make
    add_rewrite_rule(
        '^vehicles/([^/]+)/?$',
        'index.php?te_make=$matches[1]',
        'top'
    );
}
add_action( 'init', 'te_register_vehicle_routes' );

add_filter( 'query_vars', function ( $vars ) {
    $vars[] = 'te_make';
    $vars[] = 'te_model';
    $vars[] = 'te_year';
    return $vars;
} );

The data model: CPT plus taxonomies, or loose query vars

When listings are real content with bodies, images and metadata (a dealer inventory, a parts catalog), make each one a vehicle post and attach make, model and year as taxonomy terms:

php
add_action( 'init', function () {
    register_post_type( 'vehicle', array(
        'public'      => true,
        'has_archive' => true,
        'supports'    => array( 'title', 'editor', 'thumbnail', 'custom-fields' ),
        'rewrite'     => array( 'slug' => 'vehicles' ),
    ) );

    foreach ( array( 'make', 'model', 'year' ) as $taxonomy ) {
        register_taxonomy( "vehicle_{$taxonomy}", 'vehicle', array(
            'hierarchical' => false,
            'public'       => true,
            'rewrite'      => false,
        ) );
    }
} );

'rewrite' => false on the taxonomies stops WordPress generating /vehicle_make/toyota/ URLs that compete with the hand-built path. The taxonomies exist for filtering; the URL is owned by the rewrite rules. If make, model and year are just facets in post meta or an external table, skip the taxonomies and translate the query vars into a meta_query or a custom lookup instead: lighter, but you lose term archives and the admin term UI.

For the taxonomy model, pre_get_posts adds a clause only for the vars that are present, so the same code renders the listing, the model archive and the make archive:

php
add_action( 'pre_get_posts', function ( $query ) {
    if ( is_admin() || ! $query->is_main_query() ) {
        return;
    }

    $make  = $query->get( 'te_make' );
    $model = $query->get( 'te_model' );
    $year  = $query->get( 'te_year' );

    if ( ! $make ) {
        return; // not a vehicle route
    }

    $query->set( 'post_type', 'vehicle' );

    $tax_query = array( 'relation' => 'AND' );
    $tax_query[] = te_term_clause( 'vehicle_make', $make );
    if ( $model ) {
        $tax_query[] = te_term_clause( 'vehicle_model', $model );
    }
    if ( $year ) {
        $tax_query[] = te_term_clause( 'vehicle_year', $year );
    }

    $query->set( 'tax_query', $tax_query );
} );

function te_term_clause( $taxonomy, $slug ) {
    return array(
        'taxonomy' => $taxonomy,
        'field'    => 'slug',
        'terms'    => sanitize_title( $slug ),
    );
}

Keep the static prefix

It is tempting to drop vehicles/ and serve /toyota/camry/2024/ from the root. That is the same mistake as the base-less product URL above, at three levels: ^([^/]+)/([^/]+)/([^/]+)/?$ at 'top' matches the first path component of any URL, so a page at /about/team/history/ resolves to the vehicle controller with te_make=about, and date-based permalinks (/2024/08/some-post/), nested pages and deep category trees are intercepted before core sees them. The ways out mirror the product case: a static prefix (the boring correct answer), 'bottom' priority (fragile, a page that looks like a vehicle path wins), or checking in pre_get_posts that the first segment is a known make before claiming the query (the most code, and the broad rule is still tested against every URL). A rule whose regex can match the first segment of the whole site needs a static prefix or a very good reason.

Nothing here is automotive. The three segments are just a hierarchy:

DomainLevel 1Level 2Level 3Example URL
Vehiclesmakemodelyear/vehicles/toyota/camry/2024/
Electronicsbrandseriesmodel/products/sony/bravia/xr-a95l/
Partscategorysubcategorysku/parts/brakes/rotors/br-44821/
Propertiescityneighborhoodlisting/homes/austin/mueller/1423-zach/

Swap the prefix and the query var names and keep the mechanics. After flushing (next section, calling te_register_vehicle_routes() before flush_rewrite_rules()), check each level:

bash
curl -sI https://example.com/vehicles/toyota/camry/2024/ | head -n1
curl -sI https://example.com/vehicles/toyota/camry/ | head -n1
curl -sI https://example.com/vehicles/toyota/ | head -n1

To see the parsed vars rather than just the status, temporarily dump them and remove the block before shipping:

php
add_action( 'template_redirect', function () {
    if ( isset( $_GET['te_debug'] ) ) {
        global $wp_query;
        wp_die( '<pre>' . esc_html( print_r( $wp_query->query_vars, true ) ) . '</pre>' );
    }
} );

/vehicles/toyota/camry/2024/?te_debug=1 should show te_make, te_model and te_year set. Empty values mean the rule did not match (flush, regex) or another rule claimed the URL first.

Flush the rewrite rules (or nothing routes)

WordPress caches its compiled rewrite rules in the database. Adding a rule in code does not take effect until those cached rules are regenerated, so a fresh add_rewrite_rule() will 404 every clean URL until you flush.

Two ways to flush:

  • The manual one: go to Settings > Permalinks and click Save Changes without editing anything. This forces a regeneration and is the right move during development.
  • The code one: call flush_rewrite_rules() once, on plugin activation. Never call it on every init; it is an expensive write and doing it on every request is a known performance footgun.
php
register_activation_hook( __FILE__, function () {
    te_product_rewrite_rule();
    flush_rewrite_rules();
} );

For a must-use plugin (which has no activation hook), the manual Settings > Permalinks save is the pragmatic flush. See my deeper notes on the mechanics in the add_rewrite_rule walkthrough.

Verify with curl

Once the rule is flushed, test the resolve direction from the command line rather than trusting the browser cache. A working product URL returns 200:

bash
curl -I https://example.com/store/blue-widget
code
HTTP/2 200
content-type: text/html; charset=UTF-8
link: <https://example.com/wp-json/wp/v2/product/111>; rel="https://api.w.org/"

Then confirm the two failure modes you care about did not appear:

bash
# An existing page must still be itself, not a product 404:
curl -I https://example.com/about

# The old /product/ URL should redirect or 404, not silently duplicate:
curl -I https://example.com/product/blue-widget

A 200 on /store/blue-widget and a clean 200 on /about means the rule is scoped correctly. A 404 on /about after adding a base-less rule is the collision problem from above announcing itself; put a base back. If you also removed the old base, decide whether /product/blue-widget should 301 to the new URL (good for SEO, avoids duplicate-content) and add that redirect explicitly.

Technically yes, with a post_type_link filter plus an add_rewrite_rule() that maps a bare slug to post_type=product. The catch is that WordPress can then no longer tell a product apart from a page, post, or category with the same slug, so you get 404s on existing pages or the wrong content served.

To make it actually correct you have to enforce slug uniqueness across products and pages (hook wp_unique_post_slug). For most stores a short custom base like /store/ is the better trade: nearly as clean, none of the fragility.

Almost always a stale rewrite cache. WordPress compiles rewrite rules into the database and does not regenerate them just because you saved new code. Go to Settings > Permalinks and click Save Changes once (no edits needed) to force a flush, then retest.

If a base-less structure still 404s only on certain URLs, that is the slug-collision problem, not the cache: a page and a product are fighting over the same path segment.

/product/ is the base for single product URLs (the product post type). /product-category/ is the base for the product category taxonomy archives. They are separate settings on the Settings > Permalinks screen.

WooCommerce requires the two values to stay distinct so WordPress can route a product request and a category request differently. Setting both to the same word (for example shop) breaks routing.

The settings screen handles the common cases with no code: keep the default /product/, switch to your shop page slug, nest the category, or set a custom one-word base. Pick Custom base and type your prefix.

You only need code (the post_type_link filter plus a rewrite rule) for structures the UI will not produce, chiefly a truly base-less URL. If the UI gives you what you want, do not write code you then have to maintain.

Changing it on a new or low-traffic store is fine. On an established store, every existing product URL that changes needs a 301 redirect from the old URL to the new one, or you lose the ranking and any inbound links pointing at the old path.

The clean structure itself is mildly positive (shorter, more readable URLs), but the redirect hygiene during the switch matters far more than the prefix you land on. Map old to new before you flip the setting in production.

Add a 301 on template_redirect: once WordPress has resolved the doc, compare the request URL to the clean root URL and, if they differ, wp_safe_redirect() to the root form with a 301 and exit. A genuine root request already matches, so there is no loop.

Almost always because the rule has no static leading segment. A regex like ^([^/]+)/([^/]+)/([^/]+)/?$ at top priority matches the first path component of any URL, so it intercepts pages, posts, category trees and date archives before core sees them. Add a literal prefix such as ^vehicles/....

Register the shorter rules alongside the three-segment one, most specific first, at the same priority. Then have pre_get_posts add a taxonomy clause only for the query vars that are present, so one callback renders the listing, the model archive and the make archive.

See also

Sources

Authoritative references this article was fact-checked against.

TagsWordPressWooCommercePHPPermalinksRewrite RulesSEOCustom Post TypesDirectory Sites

Found this useful? Pass it on.

Copied

Ishan Karunaratne

Systems and Network Architect · Chief Technology Officer

Systems and network architect and Chief Technology Officer with more than two decades designing, building, and running production software, cloud and network architecture, Linux systems, and the bare metal underneath them, and lately working AI into the stack. A US Army veteran who served in Operation Iraqi Freedom. What I write here is drawn from the full arc of that work, across architecture, engineering, and operations, not any single job.

Keep reading

Related posts

What rockyou.txt is and where to get it, the curated wordlists worth having, how to optimise and order them, and how to generate target-specific lists with crunch, cewl, and hashcat.

Password Cracking Wordlists: RockYou and Beyond

A cracker is only as good as the candidates it tries, and the wordlist is the most important one. I cover rockyou.txt and where to get it, the curated lists worth having, how to optimise and order them, and how to build target-specific lists with crunch, cewl, and hashcat --stdout.

Run bulk operations across thousands of WordPress posts with wp eval-file or a custom WP-CLI command: batched WP_Query, flat memory, and AI batch API jobs.

Run Bulk Scripts in WordPress With WP-CLI (eval-file)

The right way to run a bulk operation across thousands of WordPress posts: a wp eval-file harness with batched queries and a flush-in-loop, measured WP_Query memory tuning, wp_insert_post imports that don't run out of memory, packaging it as a custom WP-CLI command, and pushing AI enrichment through a batch API at half the cost.