For the complete documentation index, see llms.txt. This page is also available as Markdown.

Filtering products on import

Import only part of a large feed instead of the whole catalog.

Marketplace feeds are often far larger than what you actually need. An affiliate network may only offer one broad category file — for example a single "Arts & Entertainment" feed with 1.6 million Etsy products, when your site only covers party supplies.

The import filter solves this. Products are matched before they are written to your database, so only the ones you want are stored.

Setting it up

In the module settings you'll find three fields:

  • Filter products by — which field to match against: Category, Title, or Brand.

  • Filter modeInclude matching products (keep only matches) or Exclude matching products (keep everything else).

  • Filter values — one value per line. Leave empty to import every product.

Matching is case-insensitive and partial, so you don't have to type a value exactly. This matters most for categories, which are usually hierarchical: filtering on Party Supplies also keeps Party & Celebration~~Party Supplies~~Party Games and every other subcategory beneath it. Multiple lines are combined with OR — a product is a match if it matches any one of them.

To filter by category, the category field must be mapped in Field mapping. If it isn't, there is nothing to match against and an Include filter will keep nothing.

Other settings can remove products before the filter ever sees them. Import only products in stock is the common one: if your feed's stock field holds a quantity rather than a yes/no value, only rows whose value reads as "in stock" survive, and the filter is applied to whatever is left. If a filter returns fewer products than you expect, check that setting and your stock mapping first.

After the import, the feed status shows how many rows were skipped, for example Skipped rows: 1,626,235 filtered. If that number is the entire feed, your filter matched nothing — check the mapping and the exact spelling of your values.

Changing any filter setting re-imports the feed with the new rules.

Filtering with code

When the three fields aren't enough — combining conditions, matching on price, or reading a field the UI doesn't offer — use the cegg_feed_product_filter hook. Return false to skip a product. It runs for every row, in addition to any filter configured in the settings.

add_filter('cegg_feed_product_filter', function ($keep, $product, $module_id) {

    // Only apply this to one feed module.
    if ($module_id !== 'Feed__1') {
        return $keep;
    }

    // Skip anything under 10.00.
    if ($product['price'] < 10) {
        return false;
    }

    // Keep party games, but not the printable ones.
    if (stripos($product['category'], 'Party Games') === false) {
        return false;
    }

    return stripos($product['title'], 'printable') === false;

}, 10, 3);

The $product array holds the mapped fields — title, price, category, brand, ean, orig_url, stock_status and the rest. Add the snippet to your theme's functions.php or a small custom plugin, then reload the feed data so it applies.

Last updated