PHP code example of friedolinfoerder / wp-activerecord
1. Go to this page and download the library: Download friedolinfoerder/wp-activerecord 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/ */
friedolinfoerder / wp-activerecord example snippets
// create a model class for the table {wp-prefix}slideshows
class Slideshow extends \wp_activerecord\ActiveRecord {
protected static $table_name = 'slideshows';
}
// create new row
$slideshow = Slideshow::create([
'title' => 'Header slideshow',
'slide_time' => 3000,
'slide_effect' => 'fade'
]);
// retrieve by id...
$slideshow = Slideshow::get(1);
// ... and update the row
$slideshow->title = 'New title';
$slideshow->slide_effect = 'slide';
$slideshow->save();
$activeRecords = Table::query()
->where('name', 'wp')
->where('title', 'LIKE', '%active%')
->where([
'start' => 12,
'end' => 37
])
->where(['deleted_at', null]) // query for NULL value, produces `deleted_at` IS NULL
->where('value', '>', ['RAND()']) // raw value wrapped in array
->where('numbers', 'in', [[1, 2, 3]] // a array as raw value will be joined
->get();