1. Go to this page and download the library: Download tgeorgel/objectpress 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/ */
tgeorgel / objectpress example snippets
namespace App\Wordpress\PostTypes;
use OP\Framework\Wordpress\PostType;
class Event extends PostType
{
public static string $name = 'event';
public $singular = 'Event';
public $plural = 'Events';
public $menu_icon = 'dashicons-store';
}
namespace App\Wordpress\Taxonomies;
use OP\Framework\Wordpress\Taxonomy;
class EventType extends Taxonomy
{
public static string $name = 'event-type';
public $singular = 'Event type';
public $plural = 'Event types';
protected $post_types = [
'Event',
];
}
namespace App\Models;
use OP\Framework\Models\Post;
class Event extends Post
{
/**
* Wordpress post type identifier, associated to the current model.
*/
public static $post_type = 'event';
/**
* Get this Event associated locations (taxonomy) names.
*
* @param int $limit Maximum number of terms to get
* @return array
*/
public function locations(int $limit = 5): array
{
return $this->taxonomies
->where('taxonomy', 'locations')
->take($limit)
->pluck('term.name')
->toArray();
}
}
# Get all events
$events = Event::all();
# Get all events attached to a specific taxonomy term (by slug)
$events = Event::whereHas('taxonomies', function ($query) {
$query->where('taxonomy', 'locations')
->where('term.slug', 'paris');
})->get();
# Get all events attached to a specific taxonomy term (by id) and a specific meta value
$events = Event::whereHas('taxonomies', function ($query) {
$query->where('taxonomy', 'locations')
->where('term_id', 123);
})->whereHas('meta', function ($query) {
$query->where('meta_key', 'price')
->where('meta_value', '<', 100);
})->get();
# Get published events created in the last 30 days
$events = Event::published()
->where('post_date', '>', now()->subDays(30))
->get();
namespace App\Wordpress\Commands;
use App\Classes\AlgoliaApi;
use OP\Framework\Wordpress\Command;
class WelcomeNewUsers extends Command
{
/**
* The command name called with "wp {name}"
*
* @var string
* @access protected
*/
protected string $name = 'mails:welcome-new-users';
/**
* Index coaches into algolia for website search.
*
* @param array $args The command arguments as returned by WpCLI.
* @return void
*/
public function execute(array $args = [])
{
// do something great.
}
}