PHPackages                             ncaroyannis/corcel-acf - 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. ncaroyannis/corcel-acf

ActiveLibrary

ncaroyannis/corcel-acf
======================

Advanced Custom Field (ACF) plugin for Corcel

0760PHP

Since Mar 29Pushed 2y ago1 watchersCompare

[ Source](https://github.com/ncaroyannis/corcel-acf)[ Packagist](https://packagist.org/packages/ncaroyannis/corcel-acf)[ RSS](/packages/ncaroyannis-corcel-acf/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Corcel ACF Plugin
=================

[](#corcel-acf-plugin)

[![Travis](https://camo.githubusercontent.com/84c3b6fa56f65661d0fdd362a88a25fa6c16ed517a698b16e05a587d44026772/68747470733a2f2f7472617669732d63692e6f72672f636f7263656c2f6163662e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/corcel/acf?branch=master)[![Packagist](https://camo.githubusercontent.com/84a32c9356834fb0cbd63a37b8c5e77fd26e53f60856213a4ef1e5c832773b05/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f636f7263656c2f6163662e737667)](https://github.com/corcel/acf/releases)[![Packagist](https://camo.githubusercontent.com/69241871acb418343f82a82f1eec37b7329c8890be4531ca8ec17fdb687463b3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f636f7263656c2f6163662e737667)](https://packagist.org/packages/corcel/acf)

> Fetch all Advanced Custom Fields (ACF) fields inside Corcel easily.

This Corcel plugin allows you to fetch WordPress custom fields created by the [ACF](http://advancedcustomfields.com) plugin using the same syntax of Eloquent, from the [Laravel Framework](http://laravel.com). You can use Eloquent models and Collections to improve your development, using the WordPress backend with any PHP application.

For more information about how Corcel works please visit [the repository](http://github.com/jgrossi/corcel).

- [Installation](#installation)
- [Usage](#usage)
    - [The Idea](#the-idea)
    - [What is Missing](#what-is-missing)
    - [Fields](#fields)
- [Contributing](#contributing)
    - [Running Tests](#running-tests)
- [Licence](#licence)

Version Compatibility
=====================

[](#version-compatibility)

CorcelLaravelPHP`^4.0`7.x`>=7.2``^5.0`8.x`>=7.3``^6.0`8.x`>=8.0.2`Installation
============

[](#installation)

To install the ACF plugin for Corcel is easy:

```
composer require corcel/acf

```

Corcel is required for this plugin, but don't worry, if it's missing it will be installed as well.

Usage
=====

[](#usage)

This is a development version so the usage can change further. The desired behavior of this plugin is to allow this:

```
$post = Post::find(1);
echo $post->acf->url; // returns the url custom field created using ACF
```

Performance
-----------

[](#performance)

When using something like `$post->acf->url` the plugin has to make some extra SQL queries to get the field type according ACF approach. So we created another way to get that without making those extra queries. You have only the inform the plugin what is the post type, as a function:

```
// Extra queries way
echo $post->acf->author_username; // it's a User field

// Without extra queries
echo $post->acf->user('author_username');
```

> PS: The method names should be written in `camelCase()` format. So, for example, for the field type `date_picker` you should write `$post->acf->datePicker('fieldName')`. The plugin does the conversion from `camelCase` to `snake_case` for you.

The Idea
--------

[](#the-idea)

Using the default `$post->meta->field_name` in Corcel returns the value of the `meta_value` column in the `wp_postmeta` table. It can be a string, an integer or even a serialized array. The problem is, when you're using ACF this value can be more than that. If you have an integer, for example, it can be a `post id`, an `user id` or even an array of `posts ids`.

ACF has to make 2 (two) SQL queries to find out the field type, so according the type it has different behavior with the `meta_value`. For example, if the value is `45` and the `post type` is `post_object`, the value `45` is a post with ID `45`. So, in this case, Corcel should return a `Corcel\Post` instance instead of just an integer.

First ACF fetches the `meta_value` in `wp_postmeta` table, where the `meta_key` is something like `_field_name` and the post ID is the ID of the post you want the custom field. The returned value is the `field key` and it looks like this `field_57f421a2b81bd`. With this key it fetches the corresponding post in `wp_posts`, where `post_name = 'field_57f421a2b81bd'`. With the results it gets the `post_content` value, a serialized array, deserialize it and gets the content on the `type` key. This is the field type. According it the ACF (and also this plugin) does the right thing.

This plugin works with a basic logic inside `Corcel\Acf\Field\BasicField` abstract class, that has a lot of useful functions to return the `field key`, the `value`, etc. The `Corcel\Acf\FieldFactory` is responsible to return the correct field instance according the field type, so, if the field type is `post_object` it return an instance of `Corcel\Acf\Field\PostObject`, and it will returns in the `get()` method an instance of `Corcel\Post`.

What is Missing
---------------

[](#what-is-missing)

First we should create the fields classes and the test cases. After we have to setup how Corcel is going to work with the `corcel/acf` plugin, returning the custom field value in the format `$post->meta->field` or maybe `$post->acf->field` having different behavior (done!).

- Create more unit tests for `Repeater` field;
- Implement the `Flexible Content` field with unit tests (done!);
- Improve performance. Currently the plugin makes one SQL query for each field. This goal is to improve that using `whereIn()` clauses.

Some fields are still missing (check table below and contribute).

Fields
------

[](#fields)

FieldStatusDeveloperReturnsTextok[@jgrossi](http://github.com/jgrossi)`string`Textareaok[@jgrossi](http://github.com/jgrossi)`string`Numberok[@jgrossi](http://github.com/jgrossi)`number`E-mailok[@jgrossi](http://github.com/jgrossi)`string`URLok[@jgrossi](http://github.com/jgrossi)`string`Passwordok[@jgrossi](http://github.com/jgrossi)`string`WYSIWYG (Editor)ok[@jgrossi](http://github.com/jgrossi)`string`oEmbedok[@jgrossi](http://github.com/jgrossi)`string`Imageok[@jgrossi](http://github.com/jgrossi)`Corcel\Acf\Field\Image`Fileok[@jgrossi](http://github.com/jgrossi)`Corcel\Acf\Field\File`Galleryok[@jgrossi](http://github.com/jgrossi)`Corcel\Acf\Field\Gallery`Selectok[@jgrossi](http://github.com/jgrossi)`string` or `array`Checkboxok[@jgrossi](http://github.com/jgrossi)`string` or `array`Radiook[@jgrossi](http://github.com/jgrossi)`string`True/Falseok[@jgrossi](http://github.com/jgrossi)`boolean`Post Objectok[@jgrossi](http://github.com/jgrossi)`Corcel\Post`Page Linkok[@jgrossi](http://github.com/jgrossi)`string`Relationshipok[@jgrossi](http://github.com/jgrossi)`Corcel\Post` or `Collection` of `Post`Taxonomyok[@jgrossi](http://github.com/jgrossi)`Corcel\Term` or `Collection` of `Term`Userok[@jgrossi](http://github.com/jgrossi)`Corcel\User`Google MapmissingDate Pickerok[@jgrossi](http://github.com/jgrossi)`Carbon\Carbon`Date Time Pickerok[@jgrossi](http://github.com/jgrossi)`Carbon\Carbon`Time Pickerok[@jgrossi](http://github.com/jgrossi)`Carbon\Carbon`Color Pickerok[@jgrossi](http://github.com/jgrossi)`string`Repeaterok[@jgrossi](http://github.com/jgrossi)`Collection` of fieldsFlexible Contentok[@marcoboom](http://github.com/marcoboom)`Collection`Contributing
============

[](#contributing)

All contributions are welcome. Before submitting your Pull Request take a look on the following guidelines:

- Make your changes in a new git branch, based on the `develop` branch: `git checkout -b my-fix-branch develop`;
- Create your patch/feature, including appropriate test cases. Tests are necessary to make sure what you did is working and did not break nothing in the plugin;
- Run the unit tests and ensure that all tests are passing. Please, when submitting your PR paste the results of the `phpunit` command to facilitate the approval job;
- In GitHub, send a pull request to `corcel/acf:develop`, **always**. Do not send PR to our `master` branch! We encourage you to use `git flow` () workflow to make your life easier. It' not necessary, but it'll also be good for your development career;
- Make sure your code is following the `PSR-2` conventions ().

Running Tests
-------------

[](#running-tests)

To run the phpunit tests, execute `phpunit` (if you have a global PHPUnit executable) or try the following command:

```
./vendor/bin/phpunit

```

You should import the `database.sql` file to a database inside your local environment to make the tests working. Just unzip the `tests/config/database.sql.zip` file and set the database, user and password fields in `tests/config/bootstrap.php`.

> If you want to access the WordPress Admin Panel just use username as `admin` and password `123456`.

Licence
=======

[](#licence)

[MIT License](http://jgrossi.mit-license.org/) © Junior Grossi

###  Health Score

18

—

LowBetter than 8% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity19

Early-stage or recently created project

 Bus Factor1

Top contributor holds 85.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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/8485d8a59aeabc9a260b25e3f9e48e023e2e8a74749fcd92a882a9f634b34ee4?d=identicon)[designfix](/maintainers/designfix)

---

Top Contributors

[![jgrossi](https://avatars.githubusercontent.com/u/1175275?v=4)](https://github.com/jgrossi "jgrossi (222 commits)")[![squatto](https://avatars.githubusercontent.com/u/748444?v=4)](https://github.com/squatto "squatto (8 commits)")[![tlaverdure](https://avatars.githubusercontent.com/u/1731025?v=4)](https://github.com/tlaverdure "tlaverdure (8 commits)")[![ishigami](https://avatars.githubusercontent.com/u/2190465?v=4)](https://github.com/ishigami "ishigami (5 commits)")[![omzy](https://avatars.githubusercontent.com/u/8927010?v=4)](https://github.com/omzy "omzy (4 commits)")[![jakobbuis](https://avatars.githubusercontent.com/u/949674?v=4)](https://github.com/jakobbuis "jakobbuis (4 commits)")[![ncaroyannis](https://avatars.githubusercontent.com/u/5357396?v=4)](https://github.com/ncaroyannis "ncaroyannis (3 commits)")[![marcoboom](https://avatars.githubusercontent.com/u/1839784?v=4)](https://github.com/marcoboom "marcoboom (1 commits)")[![gweecl](https://avatars.githubusercontent.com/u/44865263?v=4)](https://github.com/gweecl "gweecl (1 commits)")[![ivometz](https://avatars.githubusercontent.com/u/15211791?v=4)](https://github.com/ivometz "ivometz (1 commits)")[![chrisk-7777](https://avatars.githubusercontent.com/u/55621012?v=4)](https://github.com/chrisk-7777 "chrisk-7777 (1 commits)")[![rezsk](https://avatars.githubusercontent.com/u/34791944?v=4)](https://github.com/rezsk "rezsk (1 commits)")[![SamuelNCarvalho](https://avatars.githubusercontent.com/u/5971923?v=4)](https://github.com/SamuelNCarvalho "SamuelNCarvalho (1 commits)")

### Embed Badge

![Health badge](/badges/ncaroyannis-corcel-acf/health.svg)

```
[![Health](https://phpackages.com/badges/ncaroyannis-corcel-acf/health.svg)](https://phpackages.com/packages/ncaroyannis-corcel-acf)
```

PHPackages © 2026

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