PHP code example of jplhomer / fresa

1. Go to this page and download the library: Download jplhomer/fresa library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

jplhomer / fresa example snippets


use Fresa\PostModel;

class Event extends PostModel
{
    $postType = 'my_custom_post_type';
}

Event::register();

$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);

$event = Event::find(1);
$events = Event::where('venue', 'Times Square')
                ->order('date', 'asc')
                ->limit(5)
                ->offset(5)
                ->get();

$events->each(function($event) {
    echo $event->title;
});