php - Corcel/Laravel Eloquent 模型获取多个 post_types 结果 | WordPress

标签 php wordpress laravel eloquent

我的目标是通过 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/

相关文章:

javascript - foreach 循环未更新数据和 undefined variable 错误

android - WordPress 主题中的简单 Android 与 iOS 检测

Laravel 关系

php - 如何使用 Zend_Date 简单地更改时区偏移量?

php - 更新数组中的项目

php - 一次更新数据库中的多条记录

jquery - 我想使用 custome css 更改我的 wordpress 网站的大型菜单中 Font Awesome 图标的大小

wordpress - 如何将 wordpress 图像大小调整为固定高度和自动宽度

php - 如何使用 GET 方法将 GET 参数传递给 Laravel?

mysql - 如何使用 laravel eloquent 连接表?