我的目标是通过 Corcel 获取三种不同自定义帖子类型的所有帖子。重要的是我使用后模型而不是三个自定义模型,因为我需要事后进行排序和过滤。
我的方法(不起作用)是基于 where 函数。但这不起作用。有什么想法可以实现我想要的目标吗?
$all_posts_sorted = Post::published()->newest()->get()->where( 'post_type', '=', [ 'post_type_1', 'post_type_2', 'post_type_3' ] );
如果有另一种方法如何将三个模型(PostType1,PostType2,...)组合成一个新模型 - 我也可以接受。
最佳答案
感谢 @tim-lewis ( https://stackoverflow.com/users/3965631/tim-lewis ) 的回答
$post_types = [ 'post_type_1', 'post_type_2', 'post_type_3' ];
$all_posts_sorted = Post::published()->newest()->whereIn( 'post_type', $post_types )->get();
关于php - Corcel/Laravel Eloquent 模型获取多个 post_types 结果 | WordPress,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59880976/