I tried the advice here to separate the template’s logic into a controller. var_dump($data) in App.php outputs the data from the correct pages, but I can’t get the partial to display the posts.
Thanks! In my partial var_dump($post) in my partial now shows arrays of the post data. The only way I could figure out how to use the data was like this:
If you want each post to be represented as an object instead of an array, you can remove the $data = array_map(... stuff since that is what is creating the array-representation of each post.
So you would end up with something like this:
public function getMenuPages()
{
$args = array(
'post_type' => 'page',
'posts_per_page' => 3,
'post_parent' => 0,
'orderby' => 'menu_order',
'order' => 'DESC',
);
return (new \WP_Query($args))->posts;
}
Thank you very much @folbert and @alwaysblank. That was exactly the help I needed to tie everything together. Here’s my final working code if anyone in the future needs help making a controller to get post data for a blade template: