Php Corcel/Laravel雄辩模型获得多个post|U类型结果| WordPress

Php Corcel/Laravel雄辩模型获得多个post|U类型结果| WordPress,php,wordpress,laravel,eloquent,Php,Wordpress,Laravel,Eloquent,我的目标是通过Corcel获得三种不同自定义帖子类型的所有帖子。重要的是我要使用Post模型,而不是三个自定义模型,因为我需要在之后进行排序和筛选 我的方法——不起作用——是基于where函数的。但它不起作用。有什么想法可以实现我想要的吗 $all_posts_sorted = Post::published()->newest()->get()->where( 'post_type', '=', [ 'post_type_1', 'post_type_2', 'post_ty

我的目标是通过Corcel获得三种不同自定义帖子类型的所有帖子。重要的是我要使用Post模型,而不是三个自定义模型,因为我需要在之后进行排序和筛选

我的方法——不起作用——是基于where函数的。但它不起作用。有什么想法可以实现我想要的吗

$all_posts_sorted = Post::published()->newest()->get()->where( 'post_type', '=', [ 'post_type_1', 'post_type_2', 'post_type_3' ] );

如果有另一种方法可以将三个模型(PostType1、PostType2,…)组合成一个新模型,我也很乐意

感谢@tim lewis()


where()
方法与多个值(数组)不匹配。使用
where()
方法。另外,
->get()
返回一个
集合,在您的例子中,返回数据库中的每个记录,然后使用PHP逻辑进行过滤。考虑在<代码> >代码> >代码> > GET()>代码>以提高性能,因为在提交PHP内存之前,它将使用数据库逻辑来过滤该值。该死,这太快了!谢谢。我会用结果更新问题。没问题!乐意帮忙:)
$post_types = [ 'post_type_1', 'post_type_2', 'post_type_3' ];
$all_posts_sorted = Post::published()->newest()->whereIn( 'post_type', $post_types )->get();