简体   繁体   English

Corcel / Laravel Eloquent Model 得到多个 post_types 结果| WordPress

[英]Corcel / Laravel Eloquent Model get multiple post_types results | WordPress

My goal is to get all posts of three different custom post types via Corcel.我的目标是通过 Corcel 获取三种不同自定义帖子类型的所有帖子。 It is important that i use the Post-Model and not three custom Models, because i need to sort and filter afterwards.重要的是我使用后模型而不是三个自定义模型,因为我需要在之后进行排序和过滤。

My approach - which does not work - is based on a where function.我的方法 - 这不起作用 - 基于 where 函数。 But it does not work.但它不起作用。 Any ideas how to achieve what i am looking for?任何想法如何实现我正在寻找的东西?

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

If there is another way how to combine three Models (PostType1, PostType2,...) into one new Model - i would be fine with this too.如果有另一种方法如何将三个模型(PostType1、PostType2...)组合成一个新模型 - 我也可以接受。

Answer thanks to @tim-lewis ( https://stackoverflow.com/users/3965631/tim-lewis )感谢@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();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM