1

I'm trying to create a basic GET API using Slim and Wordpress that will return any post type, I've got it route working were it will return the 5 latest posts, per the Wordpress default.

I would like to create an end point we I can return all posts within a specific post type. With my current route I can add on any of the default WP_Query methods on to the end of it and return any number of posts through the posts_per_page= query.

After some digging and a couple of tutorials I came up with this route(to return all associated posts within a post type):

$api->get("/:type/all", function ($type) use ($api) {
$args = ['post_type' => $type, 'posts_per_page' => -1] + $api->request()->get();
$data = \app\models\WPObject::find($args);

$response = $api->response();
    $response['Content-Type'] = 'application/json';
    $response->body(json_encode($data));
});

When I try to hit the route I get a null response. I'm a Slim newbie my assumption I'm not building the $args variable correctly. I'm using Slim 2.3.3, what's the correct way to build this argument variable?

4

0 回答 0