---
name: kimaai_embedding_fetch_query_args
type: filter
since: 1.5.4
tier: premium
feature: embeddings
area: embedding-search
summary: Changes the WP_Query arguments a sync fetches its posts with, for example to leave posts out.
parameters:
  - name: query_args
    type: array
    description: The WP_Query arguments; published posts without a password by default, newest first, at most the sync's limit.
  - name: args
    type: array
    description: What the sync asked for, with post_type, post_id, post_ids, limit and modified_after.
returns:
  type: array
  description: The WP_Query arguments.
---

# kimaai_embedding_fetch_query_args

## When it fires

Once per sync of the knowledge base, before it fetches the posts to index: a sync from the Sync tab, the automatic sync of a published or updated post, `wp kimaai vectors sync` and the MCP re-embed tool. The arguments already hold the post type, the IDs or the date the sync asked for; for PDFs the status `inherit` and the PDF MIME type.

KimaAI hooks it itself: it adds a `meta_query` clause that leaves out the PDFs whose "Include this document in the chatbot knowledge base" box is unchecked in the Media Library. Add to `meta_query` rather than replacing it.

A post the query leaves out is not synced, and its chunks from an earlier sync stay in the index. To keep a post out of the index and every answer, deny it with `kimaai_content_access_tokens`: the next sync then removes its chunks.

## Example

```php
add_filter(
  'kimaai_embedding_fetch_query_args',
  function (array $query_args): array {
    // Posts with the custom field keep_out_of_chatbot are never synced.
    $query_args['meta_query'][] = [
      'key' => 'keep_out_of_chatbot',
      'compare' => 'NOT EXISTS',
    ];

    return $query_args;
  }
);
```

## Related

- `kimaai_embedding_supported_sources`: the sources the Sync tab offers.
- `kimaai_embedding_extra_text`: adds text to the posts a sync indexes.
