denisprado

payload plugin image relationship

by denisprado
Custom fields
v3
^3.56.0

Overview

Summary generated from the README

Replaces the default relationship field UI with a visual gallery that shows image thumbnails for selection. It is added to the plugins array and applies a custom field component to relationship or upload fields whose relationTo matches the configured media collection slugs. Supports single and multiple selection and requires Payload 3.56 or newer.

Features

  • Gallery-style interface with image thumbnails for selection
  • Paginated loading with a Load More button for large media libraries
  • Backend-powered search by alt text or filename
  • Supports both single and multiple selection (hasMany)
  • Selected images are sorted first and shown as a preview
  • Collapsible interface to save screen space

Use cases

  • Pick featured images for posts from a large media library using thumbnails
  • Select multiple gallery images on a page with a visual preview of the choices

From the author

A Payload CMS plugin that enhances the relationship field to support image uploads.

Installation

npm i payload-plugin-image-relationship

3

Stars

0

Forks

1

Open Issues

1 years ago

Last Updated

0

Weekly Downloads

v1.1.9

npm Version

657.1 KB

Unpacked Size

0

Dependencies

GitHub stars

Trends appear after 7 days of data. Daily snapshots have not started yet.

npm weekly downloads

Trends appear after 7 days of data. Daily snapshots have not started yet.

Each point is npm's rolling 7-day download count.

Health Score

13/100Poor

Composite score based on GitHub activity, stars, npm downloads, publish recency, dependency count, and package size.

Badge for your README

Payload Directory health badge
Markdown
[![Payload Directory](https://payloaddirectory.dev/badge/1062051009-root.svg)](https://payloaddirectory.dev/plugins/1062051009-root)
HTML
<a href="https://payloaddirectory.dev/plugins/1062051009-root"><img src="https://payloaddirectory.dev/badge/1062051009-root.svg" alt="Payload Directory"></a>
Updated Oct 17, 2025Created Sep 22, 2025Published Oct 17, 2025

README

Payload Plugin Image Relationship

A Payload CMS plugin that enhances the relationship field to support image uploads.

Features

  • Replaces the default relationship field with a visual, gallery-style interface.
  • Displays image thumbnails for easy selection.
  • Efficiently handles large media libraries with paginated loading ("Load More").
  • Backend-powered search for fast and accurate filtering by alt text or filename.
  • Supports both hasMany: false (single selection) and hasMany: true (multiple selections).
  • Selected images are sorted and displayed first.
  • Collapsible interface to save screen space.
  • Shows a preview of selected images.

Screenshot

Payload Plugin Image Relationship Screenshot

Installation

pnpm install payload-plugin-image-relationship

or

npm install payload-plugin-image-relationship

or

yarn add payload-plugin-image-relationship

Usage

In your payload.config.ts, import the plugin and add it to the plugins array.

import { buildConfig } from 'payload/config';
import { imageRelationshipPlugin } from 'payload-plugin-image-relationship';
import { Media } from './collections/Media'; // Your media collection
import { Posts } from './collections/Posts'; // A collection with a relationship to Media

export default buildConfig({
  // ...
  collections: [Media, Posts],
  plugins: [
    imageRelationshipPlugin({
      // The 'relationTo' property should match the slug of your media collection
      relationTo: 'media',
    }),
  ],
  // ...
});

The relationTo option can be a single slug or an array of slugs. The plugin will apply the custom field component to any relationship or upload field that has a relationTo property matching one of the provided slugs.

Example of a relationship field in your collection:

// In your Posts collection
import { CollectionConfig } from 'payload/types';

export const Posts: CollectionConfig = {
  slug: 'posts',
  fields: [
    {
      name: 'title',
      type: 'text',
    },
    {
      name: 'featuredImage',
      type: 'relationship',
      relationTo: 'media', // This must match the 'relationTo' in the plugin options
    },
  ],
};

Similar plugins