diff --git a/src/Fields/Settings/FilterBy.php b/src/Fields/Settings/FilterBy.php index 3ce1b24f..25776d9b 100644 --- a/src/Fields/Settings/FilterBy.php +++ b/src/Fields/Settings/FilterBy.php @@ -17,31 +17,43 @@ trait FilterBy { - public function postTypes(array $postTypes): static + /** + * @param string[] $postStatus draft, future, pending, private, publish + * @throws \InvalidArgumentException + */ + public function postStatus(array|string $postStatus): static { - $this->settings['post_type'] = $postTypes; + if (is_string($postStatus)) { + $postStatus = [$postStatus]; + } + + if (count(array_diff($postStatus, ['draft', 'future', 'pending', 'private', 'publish'])) > 0) { + throw new InvalidArgumentException('Invalid argument post status.'); + } + + $this->settings['post_status'] = $postStatus; return $this; } - public function taxonomies(array $taxonomies): static + public function postTypes(array|string $postTypes): static { - $this->settings['taxonomy'] = $taxonomies; + if (is_string($postTypes)) { + $postTypes = [$postTypes]; + } + + $this->settings['post_type'] = $postTypes; return $this; } - /** - * @param string[] $postStatus draft, future, pending, private, publish - * @throws \InvalidArgumentException - */ - public function postStatus(array $postStatus): static + public function taxonomies(array $taxonomies): static { - if (count(array_diff($postStatus, ['draft', 'future', 'pending', 'private', 'publish'])) > 0) { - throw new InvalidArgumentException('Invalid argument post status.'); + if (is_string($taxonomies)) { + $taxonomies = [$taxonomies]; } - $this->settings['post_status'] = $postStatus; + $this->settings['taxonomy'] = $taxonomies; return $this; }