forked from expresser/taxonomy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Builder.php
55 lines (43 loc) · 1.07 KB
/
Builder.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
namespace Expresser\Taxonomy;
use Expresser\PostType\Post;
use Expresser\Support\Builder as BaseBuilder;
use InvalidArgumentException;
class Builder extends BaseBuilder
{
public function find($id)
{
return $this->term($id)->first();
}
public function findAll(array $ids)
{
return $this->terms($ids)->get();
}
public function findBySlug($slug)
{
return $this->term($slug)->first();
}
public function first()
{
return $this->limit(1)->get()->first();
}
public function post($postId)
{
if (is_int($postId)) {
$this->posts([$postId]);
} else {
throw new InvalidArgumentException();
}
return $this;
}
public function posts(array $postIds)
{
$ids = wp_get_object_terms($postIds, $this->model->taxonomy, ['fields' => 'ids']);
return $this->terms($ids);
}
public function postType($postType)
{
$ids = Post::query()->type($postType)->get()->lists('ID');
return $this->posts($ids);
}
}