Table of contents :

Making ACF Fields Available to AI

100-days-of-ai-harness-for-wordpress-woocommerce-with-wpsolr-014

Table of contents :

Advanced Custom Fields (ACF) often contains the information an AI-powered search or assistant needs most: product specifications, compatibility notes, audience segments, support instructions, buying guidance, and editorial metadata. However, ACF values are normally stored as WordPress post metadata. They do not automatically become part of the content that an AI retrieval workflow can search, index, or use as context.

For a WooCommerce agency, making ACF fields available to AI means designing a reliable path from structured fields to the indexing and retrieval layers used by WPSOLR and the connected AI workflow.

Why ACF data needs explicit handling

A product description may say that a product is a replacement filter, while an ACF field contains the details that determine whether it fits a particular appliance. If only the post content is indexed, an AI assistant may retrieve the product but miss the compatibility information.

Common ACF fields that are valuable for AI-assisted WooCommerce experiences include:

  • Product dimensions, materials, and technical specifications
  • Compatibility and model-number data
  • Installation, maintenance, and troubleshooting instructions
  • Audience, use-case, and industry classifications
  • Shipping restrictions, warranty information, and compliance notes
  • Internal synonyms and alternate product terminology

The important distinction is between storing data in ACF and making that data available to the search index. ACF is the data-entry layer. WPSOLR or another search service is the retrieval layer. An AI model should receive the field values through the retrieval layer rather than being expected to inspect the WordPress database directly.

Choose which fields should be available

Do not expose every custom field automatically. Start with a field inventory and classify each field according to its purpose.

  • Searchable fields: Values that should help determine whether a document matches a query, such as compatibility models or product materials.
  • Context fields: Values that should be returned to the AI as supporting information, such as installation steps or warranty terms.
  • Filterable fields: Values that should support structured filtering, such as voltage, product type, or target industry.
  • Internal fields: Editorial, operational, or confidential values that should not be indexed or sent to an AI service.

This classification prevents accidental disclosure of internal notes and avoids filling the index with low-value metadata. It also helps an agency explain to a client why some fields are searchable text while others are represented as filters or excluded entirely.

Understand how ACF values are stored

Most ACF values are stored in the wp_postmeta table. ACF also stores reference metadata that maps a value to its field definition. For indexing purposes, the useful value is normally the field value addressed by the ACF field name, not the internal reference key.

Field types require different handling:

  • Text and textarea fields: Usually suitable for direct indexing after sanitization.
  • WYSIWYG fields: Should be converted to clean text or carefully preserved HTML, depending on the search integration.
  • Number fields: Should be indexed as numeric values when range filtering or sorting is required.
  • True/false fields: Should be mapped to consistent boolean values.
  • Image, file, and post-object fields: Usually require resolving the referenced object to a title, URL, SKU, or other meaningful value.
  • Repeater and flexible-content fields: Need to be flattened into readable text or a predictable structured representation.

For example, a repeater named compatibility_models might contain rows with manufacturer and model_number. Sending a serialized PHP array to an AI index is not useful. The value should be transformed into readable content such as “Acme — Model 200; Acme — Model 300.”

Make ACF values available to the WordPress REST API

If an external indexing or AI integration reads WordPress through the REST API, register only the fields that should be exposed. ACF PRO includes REST API options for exposing field groups, but agencies should still review the resulting response and access controls. A custom field can also be registered explicitly:

add_action( 'rest_api_init', function () {
    register_post_meta(
        'product',
        'ai_product_summary',
        array(
            'show_in_rest'      => true,
            'single'            => true,
            'type'              => 'string',
            'auth_callback'     => function () {
                return current_user_can( 'edit_posts' );
            },
            'sanitize_callback' => 'sanitize_textarea_field',
        )
    );
} );

The post type, field name, data type, and authorization callback must match the project. Public product information can have different access requirements from private editorial notes. Never expose sensitive ACF fields merely because an integration needs access to one public field.

When using ACF’s REST API support, verify the response for products, product variations, and any custom post types used by the store. A field that appears in the WordPress editor is not necessarily present in the REST response.

Configure indexing in WPSOLR

In WPSOLR, identify the custom fields that contain useful product and content data and map them into the appropriate indexed fields. The exact configuration depends on the WPSOLR version and search backend, but the implementation principles are consistent:

  1. Identify the ACF field names and the post types on which they are used.
  2. Choose whether each field should contribute to full-text relevance, facets, sorting, or returned document content.
  3. Normalize values before indexing, especially for repeaters, relationships, and rich text.
  4. Run a complete reindex after changing field mappings or transformation code.
  5. Test both the indexed document and the final search response.

Do not assume that saving an ACF field automatically updates every existing indexed document. Depending on the integration and update hooks, a content change may require an indexing event or a scheduled/full reindex. Include reindexing in deployment and content-operations procedures.

Flatten structured fields deliberately

AI retrieval works best when structured values retain their meaning and labels. A useful representation includes the field name and the value rather than only a collection of unlabelled terms.

$ai_context = array(
    'Product type'       => get_field( 'product_type' ),
    'Compatible models'  => get_field( 'compatible_models_text' ),
    'Installation notes' => wp_strip_all_tags( get_field( 'installation_notes' ) ),
);

For a repeater, build the representation explicitly:

$rows = get_field( 'compatibility_models' );
$models = array();

if ( is_array( $rows ) ) {
    foreach ( $rows as $row ) {
        $manufacturer = isset( $row['manufacturer'] ) ? $row['manufacturer'] : '';
        $model_number = isset( $row['model_number'] ) ? $row['model_number'] : '';
        $models[] = trim( $manufacturer . ' — ' . $model_number );
    }
}

$compatibility_text = implode( '; ', array_filter( $models ) );

Use a stable format across all products. Consistent labels help keyword search, embeddings, debugging, and prompt construction. If a value is intended for filtering, keep a structured copy rather than converting everything into prose.

Separate retrieval content from prompt instructions

ACF may contain editorial text such as “recommended answer” or “assistant guidance.” Treat that text as data, not as a trusted instruction. Retrieved content can be outdated, malformed, or edited by users with different permissions. The application should control the system prompt and tool permissions independently of the content returned from ACF.

A safer retrieved context might look like this:

<product>
<name>Replacement Filter 200</name>
<sku>RF-200</sku>
<compatible_models>Acme Model 200; Acme Model 300</compatible_models>
<installation_notes>Turn off the appliance before removing the old filter.</installation_notes>
</product>

The application can instruct the model to answer only from the supplied product context, identify missing information, and avoid claiming compatibility when no matching model is present. The XML-like delimiters are simply a formatting convention; the key requirement is a clear boundary between instructions and retrieved data.

Handle permissions, privacy, and deletion

Before indexing ACF data, review whether a field contains customer information, supplier pricing, internal fulfillment notes, unpublished content, or other restricted data. AI availability must follow the same publication and permission rules as the underlying WooCommerce content.

Also define what happens when a field is cleared or a product is unpublished. The corresponding indexed value must be removed or updated, not left as stale context. Test these cases:

  • A published product is updated with a changed compatibility list.
  • An ACF field is emptied.
  • A product changes from published to draft or private.
  • A product variation inherits or overrides parent-product fields.
  • An editor without administrative privileges updates a permitted field.

Test the complete AI retrieval path

Unit tests for a formatter are useful, but agencies should also test the complete path from WordPress to the AI response. Create representative products with short text, long text, empty fields, special characters, repeaters, relationships, and multilingual values.

For each test, verify:

  1. The ACF value is saved in the expected format.
  2. The value appears in the REST response or indexing payload when appropriate.
  3. The WPSOLR document contains the expected field or normalized text.
  4. A relevant query retrieves the correct product.
  5. The AI receives the field in its context and cites or uses it correctly.
  6. Restricted or deleted values are not returned.

Log field names, document identifiers, and indexing status during development, but avoid logging customer data or complete private prompts in production. A small diagnostic command that prints the normalized ACF payload for one product is often more useful than inspecting raw database rows.

Trending posts
You might also like