File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed
Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change 33namespace OOPWP \PostTypes ;
44
55use Carbon \Carbon ;
6+ use OOPWP \Terms \Category ;
7+ use WP_Term ;
68
79class Post
810{
@@ -17,6 +19,12 @@ class Post
1719 public string $ status = '' ;
1820 public string $ format = '' ;
1921 public string $ excerpt = '' ;
22+
23+ /**
24+ * @var Category[]
25+ */
26+ public array $ categories ;
27+
2028 public Carbon $ publishedDate ;
2129 public Carbon $ modifiedDate ;
2230 public \WP_Post $ parent ;
@@ -44,6 +52,7 @@ public function withAll()
4452 ->withStatus ()
4553 ->withFormat ()
4654 ->withExcerpt ()
55+ ->withCategories ()
4756 ->withPublishedDate ()
4857 ->withModifiedDate ()
4958 ->withParent ();
@@ -86,6 +95,15 @@ public function withExcerpt()
8695 return $ this ;
8796 }
8897
98+ public function withCategories ()
99+ {
100+ $ this ->categories = \array_map (function (WP_Term $ term ) {
101+ return new Category ($ term ->term_id );
102+ }, \get_the_terms ($ this ->WP_Post , 'category ' ));
103+
104+ return $ this ;
105+ }
106+
89107 public function withStatus ()
90108 {
91109 $ this ->status = $ this ->WP_Post ->post_status ;
You can’t perform that action at this time.
0 commit comments