PHPackages                             matfish/craft-entry-meta - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. matfish/craft-entry-meta

ActiveCraft-plugin[Utility &amp; Helpers](/categories/utility)

matfish/craft-entry-meta
========================

Add metadata to any element

5.1.4(1y ago)3855proprietaryPHP

Since Nov 28Pushed 1y ago1 watchersCompare

[ Source](https://github.com/matfish2/craft-entry-meta)[ Packagist](https://packagist.org/packages/matfish/craft-entry-meta)[ RSS](/packages/matfish-craft-entry-meta/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (1)Versions (28)Used By (0)

Element Meta
============

[](#element-meta)

This package adds the ability to save schemaless metadata to all element types, including custom elements.

Why?
----

[](#why)

Sometimes you'll need to attach additional information to your element (e.g Entry, Product or Category) without creating a corresponding field in Craft. Common examples include saving an identifier of the element in another system, keeping track of post views, or flagging an element as seeded for later removal.

One option would be to create a read-only field on Craft using a plugin that allows for hidden/read-only field types. However, there are multiple cons to this approach:

1. You now have a field in your section layout that does not semantically belong there.
2. It can be accessed, modified and deleted from the control panel (granted only on dev environment).
3. It is loaded when creating or editing a post, which can be easily tampered with from the developer console of the browser.
4. It does not allow for ad-hoc data that could pertain to a single post or just some posts, without creating yet another field.
5. It is saved to the `content` table, which is not its natural habitat.

Element Meta offers a more flexible, schemaless alternative, which by-passes the Craft data structure and allows you to save metadata in JSON format to a designated polymorphic table.

Installation
------------

[](#installation)

1. Include the package:

```
composer require matfish/craft-entry-meta

```

2. Install the plugin:

```
php craft plugin/install entry-meta

```

Initial Setup
-------------

[](#initial-setup)

Once installed go to the plugin's settings page (Under `Settings` in the control panel).

[![Settings Page](https://user-images.githubusercontent.com/1510460/187615962-066465b2-4318-4d81-8de7-f54c1bf0d262.png)](https://user-images.githubusercontent.com/1510460/187615962-066465b2-4318-4d81-8de7-f54c1bf0d262.png)

Select the elements you'd like to add metadata to. Note that for custom elements (as opposed to Craft's native elements) you would need to provide both the Element class and the Active Record class. E.g if you would like to enable metadata on Craft Commerce's products:

Element Class = `craft\commerce\elements\Product`

Active Record Class = `craft\commerce\records\Product`

The package will validate both classes to ensure they exist and are children of Element and ActiveRecord respectively.

Once you save the settings the plugin will add the metadata functionality to the relevant elements.

Usage
-----

[](#usage)

`$entry` below refers to an entry element (`craft\elements\Entry`).

Note that the element must be already saved in order to use metadata methods.

Set metadata (will replace existing metadata):

```
$entry->setElementMetadata([
    'foo'=>'bar'
]);
```

Add to existing metadata, or replace an existing value:

```
$entry->addElementMetadata([
    'a'=>1
]);
```

Delete metadata:

```
$entry->deleteElementMetadata();
```

Get all metadata of an entry:

```
$entry->getElementMetadata();
```

Get a specific key value:

```
$entry->getElementMetadata('foo');
```

Get nested values:

```
$entry->getElementMetadata('foo.bar');
```

Or using Twig:

```
{{entry.getElementMetadata('foo')}}
```

### Query by metadata

[](#query-by-metadata)

You can query by metadata on the active record class or the element class (e.g `craft\records\Entry`, `craft\elements\Entry`) using the methods detailed below.

Note you should first join the metadata table using the `joinMetadata` method. This is a left join, so it doesn't affect query results, just adds the metadata column.

E.g

```
{{ craft.entries().joinMetadata().whereMetadata('foo','bar') }}
```

or:

```
craft\elements\Entry::find()->joinMetadata()->whereMetadata('foo','bar')
```

or:

```
craft\records\Entry::find()->joinMetadata()->whereMetadata('foo','bar')
```

#### Filter by metadata

[](#filter-by-metadata)

##### Value

[](#value)

```
Entry::find()->whereMetadata('foo','bar');
```

For more complex queries you can also chain `orWhereMetadata` and `andWhereMetadata`.

The method defaults to the `=` operand, which you can override on the third argument. E.g:

```
Entry::find()->whereMetadata('views',0,'>');
```

##### Existence

[](#existence)

You can also check for existence of metadata **keys**:

```
Entry::find()->hasMetadata('foo');
```

Or, conversely:

```
Entry::find()->doesntHaveMetadata('foo');
```

To filter down by the existence of metadata itself, simply omit the key argument:

```
Entry::find()->hasMetadata();
```

or

```
Entry::find()->doesntHaveMetadata();
```

#### Sort by metadata

[](#sort-by-metadata)

```
Entry::find()->whereMetadata('views',0,'>')->orderByMetadata('views',false, true);
```

The second boolean argument is whether to sort in ascending order. Defaults to `true`

The third boolean argument is whether the value is an integer. Defaults to `false`

#### Nested data

[](#nested-data)

You can search and sort by nested data using the `.` syntax:

```
Entry::find()->whereMetadata('foo.bar','baz')->orderByMetadata('foobar.baz');
```

### Metadata on element editor page

[](#metadata-on-element-editor-page)

By default metadata is rendered on the sidebar along with Craft's metadata (status, created at, updated at). You can disable this behaviour via the plugin settings page.

License
-------

[](#license)

You can try Element Meta in a development environment for as long as you like. Once your site goes live, you are required to purchase a license for the plugin. License is purchasable through the [Craft Plugin Store](https://plugins.craftcms.com/entry-meta).

For more information, see Craft's [Commercial Plugin Licensing](https://craftcms.com/docs/3.x/plugins.html#commercial-plugin-licensing).

Requirements
------------

[](#requirements)

This plugin requires Craft CMS 3.7.0 or later.

Contribution Guidelines
-----------------------

[](#contribution-guidelines)

Community is at the heart of open-source projects. We are always happy to receive constructive feedback from users to incrementally improve the product and/or the documentation.

Below are a few simple rules that are designed to facilitate interactions and prevent misunderstandings:

Please only open a new issue for bug reports. For feature requests and questions open a new [Discussion](https://github.com/matfish2/craft-entry-meta/discussions) instead, and precede \[FR\] to the title.

If you wish to endorse an existing FR please just vote the OP up, while refraining from +1 replies.

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance41

Moderate activity, may be stable

Popularity20

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 94.4% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~45 days

Recently: every ~15 days

Total

26

Last Release

498d ago

Major Versions

2.0.x-dev → 3.0.02022-08-31

1.1.1 → 3.0.22022-08-31

1.x-dev → v3.x-dev2022-11-21

3.1.0 → 4.0.02023-07-30

4.1.0 → 5.0.02024-04-13

### Community

Maintainers

![](https://www.gravatar.com/avatar/ef7c699ed71e1fdeb389a1aba23f26d02a0a9b7554dd9b8375b739c0357f7339?d=identicon)[matfish2](/maintainers/matfish2)

---

Top Contributors

[![matfish3](https://avatars.githubusercontent.com/u/58558031?v=4)](https://github.com/matfish3 "matfish3 (51 commits)")[![matfish2](https://avatars.githubusercontent.com/u/1510460?v=4)](https://github.com/matfish2 "matfish2 (3 commits)")

---

Tags

craft-plugincraftcmsmetadatametadataelements

### Embed Badge

![Health badge](/badges/matfish-craft-entry-meta/health.svg)

```
[![Health](https://phpackages.com/badges/matfish-craft-entry-meta/health.svg)](https://phpackages.com/packages/matfish-craft-entry-meta)
```

###  Alternatives

[minime/annotations

The KISS PHP annotations library

229378.6k37](/packages/minime-annotations)[mhor/php-mediainfo

PHP wrapper around the mediainfo command

120574.8k7](/packages/mhor-php-mediainfo)[honeystone/laravel-seo

SEO metadata and JSON-LD package for Laravel.

34744.1k](/packages/honeystone-laravel-seo)[spiral/attributes

PHP attributes reader

233.6M45](/packages/spiral-attributes)[thomas-schulz/symfony-meta

PhpStorm meta data for expected arguments completion in symfony projects.

8957.0k](/packages/thomas-schulz-symfony-meta)[nystudio107/craft-similar

Similar for Craft lets you find elements, Entries, Categories, Commerce Products, etc, that are similar, based on... other related elements.

2675.4k1](/packages/nystudio107-craft-similar)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
