*/ class QueryServiceProvider extends ServiceProvider { private $cached = []; /** * Bootstrap any application services. * * @return void */ public function register() { $this->app->singleton('query', function () { // main page query return Query::instance($GLOBALS['wp_the_query']); }); $this->app->bind('loop', function () { // current post in "The Loop" $post = $GLOBALS['post']->ID; return $this->cached[$post] ?? $this->cached[$post] = Post::find($post); }); $this->app->singleton(Post::class, function () { return Post::find(Wordpress::id()); }); } }