Do you like Laravel’s Eloquent, RedBeanPHP, or Doctrine — but you work in WordPress?
With Taco, WordPress custom post types look and feel like models.
Import Taco via Composer or download a zip. Taco is PSR-4 autoloader compliant.
Taco also runs against lots of PHPUnit tests to ensure everything’s working properly.
Taco makes quick work of developing WordPress custom post types and custom terms.
You, the developer, get to build your models using code. And Taco automatically creates the WordPress admin interface for managing the content.
Step 1
Taco is easiest to load via Composer. Just add the Taco entry to your composer.json file, then include the Composer autoloader in your wp-config.php and initialize Taco in functions.php.
You should have the composer.json file one directory above your WordPress directory.
composer.json
{ "require": { "tacowordpress/tacowordpress": "dev-master" } }
wordpress/wp-config.php
// Composer autoloader // Add to the top of wp-config.php require_once realpath(__DIR__.'/../vendor/autoload.php');
wordpress/wp-content/your-theme/functions.php
// Initialize Taco \Taco\Loader::init();
Step 2
Each custom post type created with Taco should be it’s own plugin.
After activating your plugin in the WordPress admin interface, Taco will automatically register your post type and make it part of your admin interface.
Use the WordPress admin interface to add a test record for person with your first and last name.
wordpress/wp-content/plugins/taco_person/taco_person.php
<?php /** * Plugin Name: taco_person */ class Person extends \Taco\Post { public function getFields() { return array( 'first_name'=>array('type'=>'text'), 'last_name'=>array('type'=>'text'), ); } }
Step 3
WordPress automatically pulls a Post object into your templates, which you can pass into Taco, providing you access to all of the metadata stored by Taco.
wordpress/wp-content/themes/your-theme/single-person.php
<?php $person = Person::find($post->ID); echo sprintf( 'My name is %s %s', $person->first_name, $person->last_name );