🍓 Developing WordPress should be sweet.
Use Fresa in your plugins and themes to make interacting with the WordPress ecosystem friendly and fast.
Tested on WordPress 4.8 and requires PHP 7+. Your mileage may vary.
use Fresa\PostModel;
class Event extends PostModel
{
$postType = 'my_custom_post_type';
}
Register your custom post types in one line:
Event::register();
Interact with your post in an object-oriented fashion:
$event = new Event;
$event->title = 'Hello World.';
$event->venue = 'Times Square';
$event->save();
echo $event->id; // 1
echo $event->venue; // 'Times Square';
// Same as get_post_meta(1, 'venue', true);
And perform queries through a fluent interface:
$event = Event::find(1);
$events = Event::where('venue', 'Times Square')
->order('date', 'asc')
->limit(5)
->offset(5)
->get();
Queries return a Collection instance:
$events->each(function($event) {
echo $event->title;
});
composer require jplhomer/fresa