PHP code example of twork / query

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

    

twork / query example snippets



use Twork\Query\Query;

$query = new Query('custom-post');

$query->author('Jim')
    ->category('tech')
    ->postsPerPage(20);

foreach ($query as $postId) {
    the_title();
}


use Twork\Query\Query;

$query = new Query();

foreach ($query->fetch() as $null) {
    the_title();
}



class Post {
    protected $id;

    public function __construct() {
        $this->id = get_the_ID();
    }

    public function getId() {
        return $this->id;
    }
}

use Twork\Query\Query;

$query = new Query();

foreach ($query->fetch(Post::class) as $post) {
    echo $post->getId();
}


$query = new Query('custom-post');

$query->addArg('author_name', 'Jim');