PHP code example of frozzare / wp-xu

1. Go to this page and download the library: Download frozzare/wp-xu 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/ */

    

frozzare / wp-xu example snippets




use Xu\Model\Model;

class Post extends Model {
  
  /**
   * Get model attributes.
   *
   * @return array
   */
  public function get_attributes() {
     return [
       'title' => $this->post->post_title
     ];
  }
}

$model = xu_get_model( 'post' );

echo $post->title;

use Xu\Model\Collection;

$collection = new Collection( [$model1, $model2] );
$collcetion = Post::collection( [$model1, $model2] );

class List extends Model {
  
  /**
   * Get all posts that exists on `post` post type.
   *
   * @return \Xu\Model\Collection
   */
  public function posts() {
    return static::collection( get_posts( 'post_type=post' ) );
  }
}

$collection = ( new List )->posts();