> ## Documentation Index
> Fetch the complete documentation index at: https://learn.social.plus/llms.txt
> Use this file to discover all available pages before exploring further.

# Query Posts

> Query live post collections by target, data type, review status, deletion state, tags, and pagination options.

Use post queries to build user feeds, community feeds, review queues, and media galleries. Query results are paginated live collections on the client SDKs.

## Parameters

| Operation                  | Parameter               | Required          | Description                                                                 |
| -------------------------- | ----------------------- | ----------------- | --------------------------------------------------------------------------- |
| Query posts                | Target filter           | Context-dependent | Target type and target ID for user or community feeds.                      |
| Query posts                | Data type filter        | No                | Post content types to include, such as image, video, file, poll, or custom. |
| Query posts                | Deleted-state filter    | No                | Include or exclude deleted posts where supported.                           |
| Query posts                | Review/feed status      | No                | Published, reviewing, or declined state filters where exposed by the SDK.   |
| Query posts                | `tags`                  | No                | Tags to match when building tag-filtered feeds.                             |
| Query posts                | `includeMixedStructure` | No                | Include mixed-structure posts alongside media-type filters where supported. |
| Query posts                | `untilAt`               | No                | Time boundary for pagination where supported.                               |
| Android cache invalidation | `invalidateCache`       | No                | Android-only option to skip stale paging cache for a query.                 |

## Common Filters

| Filter               | TypeScript                             | iOS                      | Android                               | Flutter                                   |
| -------------------- | -------------------------------------- | ------------------------ | ------------------------------------- | ----------------------------------------- |
| Target               | `targetType`, `targetId`               | `targetType`, `targetId` | `.targetUser()`, `.targetCommunity()` | `.targetUser()`, `.targetCommunity()`     |
| Data type            | `dataTypes`                            | `dataTypes`              | `.dataTypes()`                        | `.types()`                                |
| Include deleted      | `includeDeleted`                       | `deletedOption`          | `.includeDeleted()`                   | `.includeDeleted()`                       |
| Review/feed status   | `feedType` with published or reviewing | `feedType`               | `.reviewStatus()`                     | `.feedType()`                             |
| Tags                 | `tags`                                 | `tags`                   | `.tags()`                             | `.tags()`                                 |
| Mixed media matching | `includeMixedStructure`                | `includeMixedStructure`  | `.includeMixedStructure()`            | Not exposed in the current public builder |
| Time boundary        | `untilAt`                              | `untilAt`                | `.untilAt()`                          | Not exposed in the current public builder |
| Invalidate cache     | Not exposed                            | Not exposed              | `.invalidateCache()`                  | Not exposed                               |

## Data Type Filters

| Platform   | Query data type values                                                                                                               |
| ---------- | ------------------------------------------------------------------------------------------------------------------------------------ |
| TypeScript | Non-text post data types through `dataTypes`, including image, video, file, poll, live stream, audio, clip, room, and custom strings |
| iOS        | String `dataTypes`; deprecated `filterPostTypes` exists but new docs should use `dataTypes`                                          |
| Android    | `AmityPost.DataType`, including text, image, video, file, poll, live stream, audio, clip, room, and custom                           |
| Flutter    | `AmityDataType.TEXT`, `IMAGE`, `VIDEO`, `FILE`, `LIVESTREAM`, `POLL`, and `CUSTOM`; no public audio, clip, or room enum values       |

## Query a Community Feed

Query a community feed with the filters your UI needs, then keep the returned live collection or stream subscription while the feed is visible.

<CodeGroup>
  ```typescript TypeScript theme={null}
  import { PostRepository } from "@amityco/ts-sdk";

  let loadNextPage: (() => void) | undefined;
  let canLoadMore = false;

  const unsubscribe = PostRepository.getPosts(
    {
      targetType: "community",
      targetId: communityId,
      dataTypes: ["image", "video", "poll"],
      includeDeleted: false,
      feedType: "published",
      sortBy: "lastCreated",
      tags: ["product", "promotion"],
      includeMixedStructure: true,
    },
    ({ data: posts, onNextPage, hasNextPage, loading, error }) => {
      if (loading) return;
      if (error) {
        handleError(error);
        return;
      }

      renderResults(posts);
      loadNextPage = onNextPage;
      canLoadMore = hasNextPage;
    },
  );

  function loadMorePosts() {
    if (canLoadMore) {
      loadNextPage?.();
    }
  }
  ```

  ```swift iOS theme={null}
  let postRepository = AmityPostRepository()
  var token: AmityNotificationToken?

  let options = AmityPostQueryOptions(
      targetType: .community,
      targetId: communityId,
      sortBy: .lastCreated,
      deletedOption: .notDeleted,
      dataTypes: Set(["image", "video", "poll"]),
      feedType: .published,
      tags: ["product", "promotion"],
      includeMixedStructure: true
  )

  token = postRepository.getPosts(options).observe { collection, error in
      showSuccessMessage(collection.snapshots.count)
  }
  ```

  ```kotlin Android theme={null}
  postRepository
      .getPosts()
      .targetCommunity(communityId = communityId)
      .dataTypes(
          dataTypes = listOf(
              AmityPost.DataType.IMAGE,
              AmityPost.DataType.VIDEO,
              AmityPost.DataType.POLL
          )
      )
      .includeDeleted(includeDeleted = false)
      .reviewStatus(AmityReviewStatus.PUBLISHED)
      .tags(tags = listOf("product", "promotion"))
      .includeMixedStructure(includeMixedStructure = true)
      .sortBy(sortOption = AmityCommunityFeedSortOption.LAST_CREATED)
      .build()
      .query()
      .subscribe(
          { pagingData -> showSuccessMessage(pagingData) },
          { error -> handleGeneralError(error) }
      )
  ```

  ```dart Flutter theme={null}
  final postLiveCollection = AmitySocialClient.newPostRepository()
      .getPosts()
      .targetCommunity(communityId)
      .types([
        AmityDataType.IMAGE,
        AmityDataType.VIDEO,
        AmityDataType.POLL,
      ])
      .includeDeleted(false)
      .feedType(AmityFeedType.PUBLISHED)
      .tags(['product', 'promotion'])
      .getLiveCollection(pageSize: 20);

  postLiveCollection.getStreamController().stream.listen((posts) {
    final count = posts.length;
  });

  await postLiveCollection.loadNext();

  if (postLiveCollection.hasNextPage()) {
    await postLiveCollection.loadNext();
  }
  ```
</CodeGroup>

## Android Cache Invalidation

Android exposes `invalidateCache(true)` on post query builders. Use it when a screen should skip stale paging cache on entry, such as after pull-to-refresh.

<CodeGroup>
  ```kotlin Android theme={null}
  postRepository
      .getPosts()
      .targetCommunity(communityId = communityId)
      .includeDeleted(includeDeleted = false)
      .invalidateCache(invalidateCache = true)
      .build()
      .query()
      .subscribe(
          { pagingData -> showSuccessMessage(pagingData) },
          { error -> handleGeneralError(error) }
      )
  ```
</CodeGroup>

## Time Boundaries

`untilAt` is available on TypeScript, iOS, and Android query surfaces. It is a time boundary for pagination. For newest-first sorting, older posts beyond the boundary are excluded; for oldest-first sorting, newer posts beyond the boundary are excluded.

<CodeGroup>
  ```kotlin Android theme={null}
  val oneWeekAgo = DateTime.now().minusDays(7)

  postRepository
      .getPosts()
      .targetCommunity(communityId = communityId)
      .untilAt(oneWeekAgo)
      .build()
      .query()
      .subscribe(
          { pagingData -> showSuccessMessage(pagingData) },
          { error -> handleGeneralError(error) }
      )
  ```
</CodeGroup>

## Notes

* For media galleries, set a data type filter and enable mixed media matching where the SDK supports it.
* For moderation review queues, use review/feed status filters and apply your app's permission checks before showing restricted states.
* Always dispose live collection subscriptions, notification tokens, or stream subscriptions when the screen is destroyed.

## Related Topics

<CardGroup cols={3}>
  <Card title="Get Posts" icon="newspaper" href="./get-post">
    Retrieve one known post or a known set of post IDs.
  </Card>

  <Card title="Viewing Content" icon="eye" href="./viewing-content">
    Render returned post content by type.
  </Card>

  <Card title="Post Review" icon="shield-check" href="../moderation/post-review">
    Review approval and declined-post flows.
  </Card>
</CardGroup>
